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

问题描述 投票:-1回答:2

我有一个散点图的热图保险丝,我想更改颜色条刻度的值。色条采用热图值(0到1100),但我想使用温度值为(6,33)的色条。如何在不更改热图外观的情况下执行此操作。我尝试使用clim,但它会更改热图的外观。这是代码:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.read_csv("data/forestfires.csv")

x_number_list = df.X.tolist()
y_number_list = df.Y.tolist()
x_number_list = np.array(x_number_list)
y_number_list = np.array(y_number_list)

area_number_list = df.area.tolist()
area_number_list = [int(round(x+1,0)) for x in area_number_list]
temperature_number_list = df.temp.tolist()
temperature_number_list = np.array(temperature_number_list)

heatmap, xedges, yedges = np.histogram2d(y_number_list, x_number_list, weights=temperature_number_list)
fig, ax1 = plt.subplots(figsize=(7,7))
im = ax1.imshow(heatmap, interpolation='bicubic', cmap='hot', origin='lower') #bicubic
ax1.scatter(x_number_list, y_number_list, s=area_number_list, color=(157/255, 173/255, 245/255, 0.9))
ax1.set_ylim(y_number_list.min()-0.5, y_number_list.max()+0.5)
ax1.set_xlim(x_number_list.min()-0.5, x_number_list.max()+0.5)

cb = plt.colorbar(im, ax=ax1, shrink=0.73)
#im.set_clim(temperature_number_list.min(), temperature_number_list.max())

plt.show()

这是结果:

enter image description here

[当我使用clim时,im.set_clim(temperature_number_list.min(), temperature_number_list.max())我得到这个结果(这是我DO N'T想要的结果:]]

enter image description here

我有一个散点图的热图保险丝,我想更改颜色条刻度的值。色条采用热图值(0到1100),但我想使用温度值为(6,33)的色条。怎么...

python python-3.x matplotlib heatmap colorbar
2个回答
0
投票

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.