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

29 views (last 30 days)
AMIT on 25 May 2024 at 5:42
Edited: DGM on 25 May 2024 at 12:53
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?
Animesh on 25 May 2024 at 9:09
Edited: Animesh on 25 May 2024 at 9:10
Hey @AMIT,
DGM on 25 May 2024 at 11:39
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.

DGM on 25 May 2024 at 12:47
Edited: DGM on 25 May 2024 at 12:53
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.
% 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
image(inpict,'xdata',xrange,'ydata',yrange)
set(gca,'ydir','normal')
hold on
% plot something over it
plot(xfn,yfn,'*');
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 = 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
% 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];
end
% plot
for k = 1:numel(S)
x = S{k}(:,1);
y = S{k}(:,2);
plot(x,y); hold on
end
grid on;
xlim(xrange)
ylim(yrange)
% plot something over it
plot(xfn,yfn,'.');
Yeah, but where exactly do those cuves lie on the original image?
They line up exactly where I chose to put them.
Related:

Categories

Find more on Visualize Data in Help Center and File Exchange

R2023b

Community Treasure Hunt

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

Start Hunting!