区分`colorbar`中的裁剪值 [英] Distinguishing clipped values in `colorbar`

查看:43
本文介绍了区分`colorbar`中的裁剪值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 pcolormesh 图,其中通过将 vmin vmax 设置为严格在所绘制的值的范围内来裁剪颜色图.有没有一种方法使关联的 colorbar 从底部和顶部分离出一块以表示相关颜色不在颜色图的范围内?

I have a pcolormesh plot wherein the color map is clipped by setting vmin and and vmax to strictly within the range of the values plotted. Is there a way to have the associated colorbar detatch a chunk from the bottom and from the top to signify that the relevant colors are outside the range of the color map?

推荐答案

是的,您需要为色条使用 extend = both 关键字,然后为颜色图设置上下颜色pcolormesh对象的

Yes, you need to use the extend = both keyword for the colorbar, and then set the over and under colors for the colormap of the pcolormesh object

import matplotlib.pyplot as plt
import numpy as np

data=np.random.rand(10,10)

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

p=ax.pcolormesh(data,vmin=0.2,vmax=0.8,cmap='gray')

p.cmap.set_over('red')
p.cmap.set_under('blue')

fig.colorbar(p,extend='both')

plt.show()

这篇关于区分`colorbar`中的裁剪值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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