Matlab Image and Plot with Unexpected Flip

我与影子孤独终老i 提交于 2019-12-02 00:16:39

The explanation is that the imagesc command, like image, sets the 'Ydir' axis property to 'reverse'.

When called with C or X,Y,C, image sets the axes limits to tightly enclose the image, sets the axes YDir property to 'reverse', and sets the axes View property to [0 90].

This means that the vertical axis values increase from the top of the axis to the bottom.

Now you can compare the two cases:

  1. If you run the contourf command by itself, you have the "normal" axis mode, with vertical axis values increasing from the bottom of the axis to the top. The vertical axis labelling in your first figure reflects that.

  2. If you plot the image with imagesc and run contour on the same figure, the vertical axis is first flipped by imagesc. The subsequent contour command operates on a flipped vertical axis, and plots accordingly. That's why the contour lines are vertically flipped with respect to case 1.

Note that the combined figure obtained in case 2 is correct. If you "visually" combined the first two images of your question (which were obtained from calling imagesc and countour independently) it would be wrong, because they have different vertical axes.

This is not exactly a problem of rotation, but more a problem of vertical flip.

If you look carefully at your first two plots, you'll see that the vertical scales are flipped, so if you combine your two plots directly (whatever the way) you will end up with what you observe, i.e. one plot that is flipped with respect to the other.

I would suggest to flip the contour plot before superposition:

hold on
image([-180 180], [-90 90], worldMap);
title('Declination at elev = 0 km');
contour(X, Y, flipud(dec0Mat), contoursAt, 'ShowText','on', 'LineWidth', 2);
colormap('Gray');

or

hold on
image([-180 180], [-90 90], worldMap);
title('Declination at elev = 0 km');
contour(X, -Y, dec0Mat, contoursAt, 'ShowText','on', 'LineWidth', 2);
colormap('Gray');

Best,

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