Matplotlib等高线图彩条

时间:2016-08-25 11:44:08

标签: python matplotlib colorbar

我正在将我的数据绘制成等高线图。计算对翻译的值起作用,因此我需要将其恢复到原始值。在代码的第四行,是重新翻译过程。 但是,当我绘制它时,颜色条显示相对值,并且只是颜色条顶部的移位值的注释。检查矩阵值非常奇怪,它包含原始值。

enter image description here

如何显示颜色条,并显示原始值?

fig=plt.figure()
v=np.linspace(-180,180,25)
x,y = np.meshgrid(v,v)
z = np.add(z,-shift)
z = z.reshape(25,25).T 
plt.contourf(x,y,z,25)
fig.suptitle(AA(prefix)+' Input Data Contour Map')
plt.xlabel('$\phi$ (deg)')
plt.ylabel('$\psi$ (deg)')
plt.xticks(np.arange(-180, 181, 30))
plt.yticks(np.arange(-180, 181, 30))                                
plt.colorbar()

更新:我使用set_ticklabels()进行临时修复,其中labels是自定义标签列表。

但我仍在寻找更好的方法来解决这个问题。

plt.colorbar().set_ticklabels(labels)

updated contour map

1 个答案:

答案 0 :(得分:1)

Matplotlib不了解您的shift变量。它选择以这种方式绘制,因为您尝试可视化的更改是背景值的10 ^( - 6)。

您可以强制使用颜色栏在特定位置打勾,就像在this pylab example中使用:

一样
cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
cbar.ax.set_yticklabels(['< -1', '0', '> 1'])  # vertically oriented colorbar

然而,这样做会使比例很难阅读。