Clear Filters
Clear Filters

how to plot the data over an image of graph to validate the data?

11 views (last 30 days)
I want to plot the data that i got from my simulation over this graph to validate it. I want to know how to do it?
DGM on 25 May 2024
Transcribe the image to get a set of estimated data points. Plot the estimated data as usual instead of trying to get the plot to align with the image. Trying to do that will be at least as difficult and it will look like confusing garbage.

Sign in to comment.

Accepted Answer

DGM on 25 May 2024
Edited: DGM on 25 May 2024
You can plot things over an image, but good luck guessing whether or not your image features actually line up with the coordinate space or if they're off by half a line width.
inpict = imread('2122511.png');
% box coordinates in px
r = [43.51 15.51 214.98 153.98];
% box coordinates in data
xrange = [0 4.5];
yrange = [-0.2 0.4];
% crop the image
inpict = imcrop(inpict,r);
% flip the image
inpict = flipud(inpict);
% display the image
hold on
% plot something over it
load fakedata
Why make a blurry, questionably-aligned stack of objects when you can do this? It's still an estimation, but it's clean, and you can be as deliberate as you want in making sure the transcription matches the image.
% using the following FEX tools:
% filename of manually-fit svg file
fname = '2122511.svg.fakeextension.txt';
% data range from original image axis labels
% this is where the rectangle is drawn in the SVG
xrange = [0 4.5];
yrange = [-0.2 0.4];
% spline discretization parameter [0 1]
coarseness = 0.01;
% get plot box geometry
str = fileread(fname);
str = regexp(str,'((?<=<rect)(.*?)(?=\/>))','match');
pbx = regexp(str,'((?<=x=")(.*?)(?="))','match');
pby = regexp(str,'((?<=y=")(.*?)(?="))','match');
pbw = regexp(str,'((?<=width=")(.*?)(?="))','match');
pbh = regexp(str,'((?<=height=")(.*?)(?="))','match');
pbrect = [str2double(pbx{1}{1}) str2double(pby{1}{1}) ...
str2double(pbw{1}{1}) str2double(pbh{1}{1})];
% get coordinates representing the curve
S = loadsvg(fname,coarseness,false);
% if there are multiple paths you want to extract
% you'll need to do do the rescaling, etc for each element of S
for k = 1:numel(S) % there are multiple curves
x = S{k}(:,1);
y = S{k}(:,2);
% rescale to fit data range
x = xrange(1) + diff(xrange)*(x-pbrect(1))/pbrect(3);
y = yrange(1) + diff(yrange)*(pbrect(4) - (y-pbrect(2)))/pbrect(4);
% get rid of nonunique points
% this may or may not be needed depending on the shape
% of the curves and how they're to be processed
[x,idx,~] = unique(x,'stable');
y = y(idx);
% shove the prepared data back into S for later
S{k} = [x y];
% plot
for k = 1:numel(S)
x = S{k}(:,1);
y = S{k}(:,2);
plot(x,y); hold on
grid on;
% plot something over it
load fakedata
Yeah, but where exactly do those cuves lie on the original image?
They line up exactly where I chose to put them.

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!