设置matplotlib颜色条范围 [英] Setting matplotlib colorbar range

查看:109
本文介绍了设置matplotlib颜色条范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to set the matplotlib colorbar range. Here's what I have so far:

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()

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

How do I set the colorbar limits here?

推荐答案

Arg.它始终是您尝试的最后一件事:

Arg. It's always the last thing you try:

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

有效.

这篇关于设置matplotlib颜色条范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆