python - 设置 matplotlib 颜色栏范围

标签 python matplotlib

我想设置 matplotlib 颜色栏范围。到目前为止,这是我所拥有的:

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(20)
y = np.arange(20)
data = x[:-1,None]+y[None,:-1]

fig = plt.gcf()
ax = fig.add_subplot(111)

X,Y = np.meshgrid(x,y)
quadmesh = ax.pcolormesh(X,Y,data)
plt.colorbar(quadmesh)

#RuntimeError: You must first define an image, eg with imshow
#plt.clim(vmin=0,vmax=15)  

#AttributeError: 'AxesSubplot' object has no attribute 'clim'
#ax.clim(vmin=0,vmax=15) 

#AttributeError: 'AxesSubplot' object has no attribute 'set_clim'
#ax.set_clim(vmin=0,vmax=15) 

plt.show()

如何在此处设置颜色条限制?

最佳答案

精氨酸。这总是你尝试的最后一件事:

quadmesh.set_clim(vmin=0, vmax=15)

有效。

关于python - 设置 matplotlib 颜色栏范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15282189/

相关文章:

python - python 与 MySQL 接口(interface)的最佳方式

python - "pip install matplotlib": "“python setup.py egg_info” failed with error code 1"while installing matplotlib

python - 如何进行这个 pandas 查询?

python - 使用 np.vectorize 时出现 ValueError - 我哪里出错了?

Python:float() 参数必须是字符串或数字,而不是“pandas”

python - Python 中的自定义颜色图

html - 在 HTML 表格中,如何使用 python 在 jupyter notebook 中的绘图旁边添加文本?

python - Matplotlib 颜色

python - Spark : IllegalArgumentException: 'Unsupported class file major version 55'

python - 从列表的开头和结尾弹出多个项目