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

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?

2 commentaires

Animesh
Animesh le 25 Mai 2024
Modifié(e) : Animesh le 25 Mai 2024
Hey @AMIT,
The following MATLAB Answer might be helpful: https://www.mathworks.com/matlabcentral/answers/274926
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.

Connectez-vous pour commenter.

 Réponse acceptée

DGM
DGM le 25 Mai 2024
Modifié(e) : DGM le 25 Mai 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
image(inpict,'xdata',xrange,'ydata',yrange)
set(gca,'ydir','normal')
hold on
% plot something over it
load fakedata
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:
% https://www.mathworks.com/matlabcentral/fileexchange/72225-load-svg-into-your-matlab-code
% 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];
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
load fakedata
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:

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Produits

Version

R2023b

Question posée :

le 25 Mai 2024

Modifié(e) :

DGM
le 25 Mai 2024

Community Treasure Hunt

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

Start Hunting!

Translated by