简体   繁体   English

Python Matplotlib颜色条范围

[英]Python matplotlib colorbar range

So, after searching for a few hours, I can't seem to find a simple answer to my issue. 因此,经过几个小时的搜索,我似乎无法找到解决问题的简单答案。 I have a filled contour plot (contourf) for whom I want the values displayed on the colorbar to be between -45 and 45. 我有一个填充的轮廓图(contourf),我希望该颜色图上显示的值在-45至45之间。

fig, ax = plt.subplots()
plt.contourf(time_array, f, half_CP, 30, cmap=cm.seismic, vmin=-45, vmax=45)
cb = plt.colorbar()
plt.clim(-45,45)

clim has successfully compressed the range of colors displayed in my colorbar, however my colorbar is still displaying values from around -80 to 80... in other words, my vmin/vmax isn't working. clim已成功压缩了我的颜色栏中显示的颜色范围,但是我的颜色栏中仍显示从-80到80左右的值...换句话说,我的vmin / vmax无法正常工作。 I've tried putting this argument in the plt.colorbar line, however that has had no effect either. 我尝试将此参数放在plt.colorbar行中,但是也没有任何效果。

I would not be surprised if it's something super-simple, but I've been trying to find the error/mistake/what I'm missing for a few hours now. 如果它超级简单,我不会感到惊讶,但是几个小时以来,我一直在尝试查找错误/错误/失踪的内容。 I would appreciate any help! 我将不胜感激任何帮助!

I usually define a number of levels to contour, which also limits the range of the colorbar. 我通常会定义多个轮廓级别,这也限制了颜色栏的范围。

levels = np.arange(-45,45,1)
CS1 = plt.contourf(x,y,z,levels,cmap=cm.get_cmap('RdYlBu_r',len(levels)-1), extend='both')
plt.colorbar(CS1,orientation='vertical',shrink=0.5, format='%.2f')

Hope this helps. 希望这可以帮助。 Cheers, Trond 干杯,特隆

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

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