如何指定颜色栏范围并保持其大小而与绘图值无关 [英] How to specify colorbar range and keep it regardless of plotting values
问题描述
我昨晚输入了此内容,然后在我要提交时,我弄清楚了.提交以防其他人需要.
I typed this up last night then as I was about to submit it I figured it out. Submitting in case anyone else needs it.
我正在底图上连续几天绘制每小时的气象值.
I am plotting meteorological values for every hour for multiple days on basemap.
我想在每张地图上始终保持相同的颜色条值.假设每个地块的取值范围是0-10.
I want to keep the same values of the colorbar at all times for each map. Lets say from 0-10 for each plot.
有时这些值都非常接近零,而其他值则在0-10之间.
Sometimes the values are all very close to zero and others they range from 0-10.
for file in files:
ncfile = Dataset(file)
cbarticks=np.arange(0.0,10.0,0.5)
bm.contour(x, y, to_np(energyproduction), 10, colors="black",vmin=0,vmax=10.0)
bm.contourf(x, y, to_np(energyproduction), 10,cmap = get_cmap('jet'),vmin=0,vmax=10.0)
plt.colorbar(shrink=.62,ticks=cbarticks)
plt.show()
我将其设置为使最小值和最大值始终为0和10.刻度线始终为0-10(以0.5为增量).如何强制颜色条保持不变.
I have it set so that the min and max values are always 0 and 10. And that the ticks are always 0-10 by increments of 0.5. How can I force the colorbar to stay the same.
我希望颜色栏始终具有相同的
I would prefer that the colorbar always has the same range of
推荐答案
问题出在我的outline()和Contourf()中.在此之前,我在函数中传递了10.
The issue was in my contour() and contourf(). Prior I was passing a 10 within the function.
bm.contour(x, y, to_np(energyproduction), 10, colors="black",vmin=0,vmax=10.0)
bm.contourf(x, y, to_np(energyproduction), 10,cmap = get_cmap('jet'),vmin=0,vmax=10.0)
10表示在曲线图的最小值和最大值之间有10步.因此,如果只有0-1的值,则将以.1的增量绘制等高线.
The 10 designation means that there are 10 steps between the min and max value of the plot. So if there are only values of 0-1 you will get .1 increments of plotting contours etc.
将10删除并使其显示在Cbarticks上,我可以为每个图获得相同的颜色条值,而不管其值如何.
Be removing 10 and seeing it to cbarticks, I was able to get the same colorbar values for each plot regardless of the values.
for file in files:
ncfile = Dataset(file)
cbarticks=np.arange(0.0,10.0,0.5)
bm.contour(x, y, to_np(energyproduction), cbarticks, colors="black",vmin=0,vmax=10.0)
bm.contourf(x, y, to_np(energyproduction), cbarticks, cmap = get_cmap('jet'),vmin=0,vmax=10.0)
plt.colorbar(shrink=.62,ticks=cbarticks)
plt.show()
我相信这与底图轮廓内的级别"相同.
I believe this is the same designation of "levels" within basemap contour.
这篇关于如何指定颜色栏范围并保持其大小而与绘图值无关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!