0

I'm trying to draw 2-d contours of a 2d matrix. I am curious to know if it is normal that imshow() and contour()/contourfc() of matplotlib package work differently with respect the origin of the matrix coordinates. It appears that imshow() treats the origin of coordinates flipped with respect to contour().

I illustrate this with a quite simple example:

    import numpy as np
    from matplotlib import pyplot as plt

    a = np.diag([1.0, 2, 3])
    plt.imshow(a)

produces a nice picture with colors along the main diagonal (from left-upper corner to right-bottom corner), But if instead I execute

    plt.contour(a)

the figure is a set of contours aligned along the perpendicular diagonal (form left-bottom corner to upper-right corner).

If I flip the array with numpy flipud() function

    plt.contour(np.flipud(a))

then both contour() and imgshw() coincide.

Maybe is a stupid question, I apologize for that !

Thanks anyway

user1259970
  • 333
  • 3
  • 14
  • The default behaviour for images is apparently to plot from top left (see e.g. http://stackoverflow.com/questions/14320159/matplotlib-imshow-data-rotated, http://stackoverflow.com/questions/31823815/matlab-image-and-plot-with-unexpected-flip) while scientific data the origin is typically taken to be the bottom left... This is the same behaviour as matlab. – Ed Smith Apr 18 '16 at 16:21
  • Rather than flipping the data, which has led to confusion for me in the past, I now use `origin='lower'`. – roadrunner66 Apr 18 '16 at 16:53
  • Thanks for both answers ! – user1259970 Apr 19 '16 at 07:47

0 Answers0