问题
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