Matlab Image and Plot with Unexpected Flip

前端 未结 2 1310
花落未央
花落未央 2021-01-22 12:48

In the examples below, there are some obvious code differences in each case, but I don\'t understand how they would change the orientation of the image or the plot, as shown in

2条回答
  •  误落风尘
    2021-01-22 13:36

    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.

提交回复
热议问题