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

조회 수: 4 (최근 30일)
AMIT
AMIT 2024년 5월 25일
편집: DGM 2024년 5월 25일
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
Animesh
Animesh 2024년 5월 25일
편집: Animesh 2024년 5월 25일
Hey @AMIT,
The following MATLAB Answer might be helpful: https://www.mathworks.com/matlabcentral/answers/274926
DGM
DGM 2024년 5월 25일
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
DGM 2024년 5월 25일
편집: DGM 2024년 5월 25일
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:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by