调整 matplotlib 中的颜色条图例限制

问题描述 投票:0回答:0

我有以下 python 代码来绘制曲面等高线图:

import matplotlib.pyplot as plt
from matplotlib import cm
import pandas as pd

dx = {'1': 1, '2': -1, '3': -1, '4': 1, '5': 0}
x = pd.Series(data=dx, index=['1', '2', '3', '4', '5'])

dy = {'1': 1, '2': 1, '3': -1, '4': -1, '5': 0}
y = pd.Series(data=dy, index=['1', '2', '3', '4', '5'])

dT = {'1': 10, '2': 20, '3': 30, '4': 40, '5': 50}
T = pd.Series(data=dT, index=['1', '2', '3', '4', '5'])

plt.figure(figsize=(10,8))
plt.tricontourf(x, y, T, cmap=cm.turbo)
plt.colorbar(extend='both')

这会产生以下情节:

enter image description here

但是,我希望颜色条介于 0 到 100 之间。

所以,我添加了以下内容

plt.clim(0,100)

这样做,给了我以下情节:

enter image description here

如何将颜色条图例也更改为 0-100?

matplotlib legend colorbar
© www.soinside.com 2019 - 2024. All rights reserved.