- 积分
- 5344
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-8-28
- 最后登录
- 1970-1-1
|
发表于 2020-7-28 12:18:51
|
显示全部楼层
本帖最后由 Masterpiece 于 2020-7-28 17:13 编辑
我讲明白了么?extend是要设置在contourf里边的,而不是colorbar!
- import numpy as np
- import matplotlib.pyplot as plt
- N = 37
- x, y = np.mgrid[:N, :N]
- Z = (np.cos(x*0.2) + np.sin(y*0.3))
- fig, axl = plt.subplots(2,2,figsize=(12,9))
- extend=['neither','min','max','both']
- count=0
- for i in range(2):
- for j in range(2):
- ax=axl[i,j]
- cf=ax.contourf(x,y,Z,cmap='jet',levels=np.arange(-1.9,2.0,0.1),extend=extend[count])
- cb = plt.colorbar(cf, ax=ax, shrink=0.8, orientation='vertical')
- cb.ax.tick_params(labelsize=12, direction='out', pad=1, labelcolor='k')
- if i==1 & j==1:
- ax.set_title('extend=%s\nChange ticks=np.arange(-2,2.5,0.5)'%extend[count], fontdict={'size': 14, 'color': 'b'})
- cb.set_ticks(np.arange(-2, 2.5, 0.5))
- else:
- ax.set_title('extend=%s'%extend[count], fontdict={'size': 14, 'color': 'b'})
- count+=1
- plt.subplots_adjust(wspace=0.2,hspace=0.3)
- plt.show()
复制代码
|
|