0

I have below plot my data is 2D array from range 0 to 10 but I want my plot's axis be between [0,1] how can I change the scale? besides how can I upside down Y axis?

mydata = np.zeros((10,10))
#fill mydata
im = plt.imshow(mydata,interpolation='bilinear', aspect='auto') 
plt.colorbar(im, orientation='vertical')
plt.show()

enter image description here

Am1rr3zA
  • 7,115
  • 18
  • 83
  • 125

2 Answers2

2
  • The extent parameter alters the ticks displayed on the imshow plot. The extent should be passed a 4-tuple or list with the following meaning: extent=(xmin, xmax, ymin, ymax).
  • The y-axis can be inverted by passing origin='lower' to imshow.

import numpy as np
import matplotlib.pyplot as plt

mydata = np.random.random((10,10))

im = plt.imshow(mydata,interpolation='bilinear', aspect='auto',
                origin='lower', extent=[0, 1, 0, 1]) 
plt.colorbar(im, orientation='vertical')
plt.show()

enter image description here


Another way to invert the yaxis is to call ax.invert_yaxis. See (here) and (here) for examples.

Community
  • 1
  • 1
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
0

use plt.xticks(np.arange(5,50,5))