python的matplotlib画图库参考自matlab,但是功能更加强大,色标更加丰富,颜色更加自然,线条更加流畅。
matplotlib中的色标种类介绍
下面给几个链接,对matplotlib色标总结得比较全面:
matlabmatlab与matplotlib作图的区别:
matlab与matplotlib作图比较
Matplotlib(一)与Matlab在绘图上的对比
例子:
如何使用呢?
import matplotlib.pyplot as plt
import numpy as np
n=1024
t = np.linspace(0, 2 * np.pi, n)
data2d = np.reshape(np.sin(t),[n,1]) * np.reshape(np.cos(t),[1,n])
fig, ax = plt.subplots(1,2,figsize=(14/2.54,4/2.54))
im = ax[0].imshow(data2d,cmap='bwr')
fig.colorbar(im, ax=ax[0], label='in bwr model',extend='both')
im = ax[1].imshow(data2d,cmap='bwr_r')
fig.colorbar(im, ax=ax[1], label='in bwr_r (reverse) model',extend='both')
plt.rcParams['font.size'] = 6
plt.show()
运行结果:
其中原色标是bwr
,如需将色标逆转,只需在原色标后加_r
,即bwr_r
。同样,如果原色标是hot
,逆转色标为hot_r
。
附录:色标详情
matplotlib官网链接:https://matplotlib.org/stable/gallery/color/colormap_reference.html