matlab plot image as background to graph

假如想象 提交于 2019-12-02 05:08:32

问题


I have an image that I would like to set as the background of plot I am making. However it plots it so that the image taks up the axis([0 1000 0 1000]) while the axis for my graph is much smaller: ([24.5 24.6 67 67.1]). How do I align it so that the image is on the same scale as the graph?

I am performing the following commands:

h = figure;
hold on
voronoi(lats,longs);
I=imread('my_fig.png');
hi = imagesc(I);
set(hi,'alphadata',.5);

回答1:


You can just call image with the right x and y vectors, like so (assuming your data is in x and y):

xImg = linspace(min(x), max(x), size(I, 2));
yImg = linspace(min(y), max(y), size(I, 1));
image(xImg, yImg, I, 'CDataMapping', 'scaled');
hold on;
plot(x, y);

In other words, generate a vector for each of the dimensions of the image that has the same number of points as that dimension of the image but goes between the range of your data.



来源:https://stackoverflow.com/questions/16224532/matlab-plot-image-as-background-to-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!