how to plot the data over an image of graph to validate the data?
7 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1703666/image.png)
2 个评论
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
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1703821/image.png)
They line up exactly where I chose to put them.
Related:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Visualize Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!