简体   繁体   English

设置颜色条 matplotlib 的标签

[英]Setting the labels of colorbar matplotlib

I have spent a couple hours trying to figure this out.我花了几个小时试图弄清楚这一点。 I want the colorbar to display three values along the bar, [0, 3315/2, 3315].我希望颜色条沿着条显示三个值,[0, 3315/2, 3315]。 However, I am just getting this result:但是,我只是得到这个结果:

在此处输入图片说明

Code:代码:

print(max(average_powers)) # 3314.455810547
sm = plt.cm.ScalarMappable(cmap=cmap)
sm.set_array([])
mn=int(np.floor(0)) 3 
mx=int(np.ceil(max(average_powers)))
md=(mx-mn)/2
cb = plt.colorbar(sm)
cb.set_ticks([mn,md,mx])
cb.set_ticklabels([mn,md,mx],update_ticks=True)
cb.set_label('Magnitude of Average Power for turbine')

Thanks in advance!提前致谢!

Replace代替

cb.set_ticks([mn,md,mx])

With

cb.set_ticks([0, 0.5, 1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM