在没有颜色条的情况下,contourf 不会显示级别范围之外的颜色

问题描述

我正在尝试使用选项“extend=both”制作一些轮廓图形。 但是,颜色范围(最大和最小)之外的颜色没有显示在图中。 在contourf之后调用colorbar函数时,出现了外面的颜色,但是我想做没有colorbar的图形。

这是示例代码

import numpy as np
import matplotlib.pyplot as plt

x=np.arange(10)
y=np.arange(10)

z=np.zeros((10,10))
for n in range(10):
    for m in range(10):
        z[n,m]=x[n]*y[m]

N=255.
rgb=[(187/N,220/N,200/N),(120/N,185/N,171/N),( 52/N,150/N,142/N),( 26/N,105/N,95/N)] 

interval=[1,5,10,20,50]

cf=plt.contourf(x,y,z,colors=rgb,levels=interval,extend='both')
cf.cmap.set_under((255/N,255/N,229/N))
cf.cmap.set_over((0/N,60/N,48/N))
#plt.colorbar()

plt.savefig('test1')
plt.close()

cf=plt.contourf(x,48/N))
plt.colorbar()

plt.savefig('test2')
plt.close()

enter image description here

enter image description here

test1.png 不显示外部颜色(50)。我想得到像 test2.png 这样的图形,但没有颜色条。

有人知道如何解决这个问题吗?

我的环境是, 蟒蛇=3.6.9 Matplotlib=2.1.1

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)