如何在不更改python matplotlib中的热图的情况下更改colorbar的值?

如何在不更改python matplotlib中的热图的情况下更改colorbar的值?,python,python-3.x,matplotlib,heatmap,colorbar,Python,Python 3.x,Matplotlib,Heatmap,Colorbar,我有一个散点图的热图保险丝,我想更改颜色条刻度的值。颜色条的热图值为0到1100,但我想要一个温度值为6,33的颜色条。我怎样才能在不改变热图外观的情况下做到这一点。我试图用它来改变热图的外观。代码如下: 作为pd进口熊猫 将matplotlib.pyplot作为plt导入 将numpy作为np导入 df=pd.read_csvdata/forestfires.csv x\u编号\u列表=df.x.tolist y\u编号\u列表=df.y.tolist x\u编号\u列表=np.arrayx\

我有一个散点图的热图保险丝,我想更改颜色条刻度的值。颜色条的热图值为0到1100,但我想要一个温度值为6,33的颜色条。我怎样才能在不改变热图外观的情况下做到这一点。我试图用它来改变热图的外观。代码如下:

作为pd进口熊猫 将matplotlib.pyplot作为plt导入 将numpy作为np导入 df=pd.read_csvdata/forestfires.csv x\u编号\u列表=df.x.tolist y\u编号\u列表=df.y.tolist x\u编号\u列表=np.arrayx\u编号\u列表 y_编号列表=np.arrayy_编号列表 区域编号列表=df.area.tolist 区域编号列表=[区域编号列表中x的插入x+1,0] 温度\编号\列表=df.temp.tolist 温度编号列表=np.阵列温度编号列表 热图,xedges,yedges=np.Historogram2DY_编号列表,x_编号列表,权重=温度编号列表 图,ax1=plt.子批次IGSIZE=7,7 im=ax1.imshowheatmap,插值为双三次曲线,cmap为热曲线,原点为下三次曲线 ax1.scatterx\u编号列表,y\u编号列表,s=区域编号列表,颜色=157/255,173/255,245/255,0.9 ax1.设置我的编号列表。最小值-0.5,y编号列表。最大值+0.5 ax1.设置\u xlimx\u编号\u列表。最小值-0.5,最大值+0.5 cb=plt.colorbarim,ax=ax1,收缩率=0.73 im.set\u climtemperature\u number\u list.min、temperature\u number\u list.max 节目 结果如下:

[[33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0]]
当我使用clim、im.set\u climtemperature\u number\u list.min、temperature\u number\u list.max时,我得到了这个结果这是我不想要的结果:

试一试

将颜色条限制设置为6到33之间

在你的情况下是这样的

cb = plt.colorbar(im, ax=ax1, shrink=0.73)
cb = plt.clim(6,33)

plt.show()

我希望有帮助。这应该不会影响热图的外观。

我找到了一个解决方案,这是一个棘手的问题,但如果你有任何其他比我更好的选择,我将继续讨论这个话题

我创建了一个与第一个相同维度的假热图,但我把我的范围放在了假热图中。下面是代码:

x\u编号\u列表=df.x.tolist y\u编号\u列表=df.y.tolist x\u编号\u列表=np.arrayx\u编号\u列表 y_编号列表=np.arrayy_编号列表 区域编号列表=df.area.tolist 区域编号列表=[区域编号列表中x的插入x+1,0] 温度\编号\列表=df.temp.tolist 温度编号列表=np.阵列温度编号列表 热图,xedges,yedges=np.Historogram2DY_编号列表,x_编号列表,权重=温度编号列表 创建假热图 colorbar_参数_by_温度=[] 对于rangelenheatmap中的i: colorbar_参数_by_temperature.append[0]*lenheatmap[0] colorbar_参数_by_温度[i][0]=温度_编号_list.max colorbar_参数_by_temperature[i][1]=温度_number_list.min 图,ax1=plt.子批次IGSIZE=7,7 im=ax1.imshowheatmap,插值为双三次曲线,cmap为热曲线,原点为下三次曲线 im2=ax1.imshowheatmap2,插值='spline16',cmap='hot',原点='lower' im=ax1.imshowheatmap,插值='spline16',cmap='hot',原点='lower' ax1.scatterx\u编号列表,y\u编号列表,s=区域编号列表,颜色=157/255,173/255,245/255,0.9 ax1.设置我的编号列表。最小值-0.5,y编号列表。最大值+0.5 ax1.设置\u xlimx\u编号\u列表。最小值-0.5,最大值+0.5 cb=plt.colorbarim2,ax=ax1,收缩率=0.73 节目 结果如下:

[[33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0], [33.3, 2.2, 0, 0, 0, 0, 0, 0, 0, 0]]

您的代码第二个代码不起作用,下面是错误:RuntimeError:您必须首先定义一个映像,例如,使用imshow。但在帖子中我明确表示我不想使用clim,也许我应该举一个使用clim函数的visual的例子。我没有找到任何关键字/函数来解决您的问题。这可能是一个不好的解决方法,但您可以创建一个新的颜色栏:cmap=mpl.cm.hot | norm=mpl.colors.Normalizevmin=temperature\u number\u list.min,vmax=temperature\u number\u list.max | ax2=fig.add\u轴[1,0.3,0.05,0.5]| cb1=mpl.colorbaseax2,cmap=cmap,norm=norm=norm,ority='vertical'