Changing tick labels without affecting the plot

余生颓废 提交于 2019-12-02 01:03:10

Use the extent argument of imshow to set the x and y ranges of the image, and use aspect='auto' to allow the aspect ratio of the image to be adjusted to fit the figure. For example, the following code

In [68]: from scipy.ndimage.filters import gaussian_filter

In [69]: np.random.seed(12345)

In [70]: a = np.random.randn(27, 36)

In [71]: b = gaussian_filter(a, 4)

In [72]: ymin = 0

In [73]: ymax = 1

In [74]: plt.imshow(b, origin='lower', extent=[-90, 90, ymin, ymax], aspect='auto')
Out[74]: <matplotlib.image.AxesImage at 0x1115f02d0>

In [75]: plt.xticks([-90, -60, -30, 0, 30, 60, 90])
Out[75]: 
([<matplotlib.axis.XTick at 0x108307cd0>,
  <matplotlib.axis.XTick at 0x1101c1c50>,
  <matplotlib.axis.XTick at 0x1115d4610>,
  <matplotlib.axis.XTick at 0x1115f0d90>,
  <matplotlib.axis.XTick at 0x1115ff510>,
  <matplotlib.axis.XTick at 0x11161db10>,
  <matplotlib.axis.XTick at 0x111623090>],
 <a list of 7 Text xticklabel objects>)

generates this plot:

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