简体   繁体   English

设置用于使用matplotlib contourf绘制的数组蒙版值的颜色

[英]Set color to be used for an array masked values plotted with matplotlib contourf

When I plot an array with masked values, using matplotlib countourf , the masked values appear white. 当我使用matplotlib countourf绘制具有蒙版值的数组时,蒙版值显示为白色。 I want them to appear grey. 我希望它们显得灰色。

I tried the set_bad method, but it seems countourf doesn't recognize it (although it recognizes the set_over and set_under methods). 我试过set_bad方法,但似乎countourf不承认它(尽管它承认set_overset_under方法)。

Is there any other method I can use with contourf ? 有没有其他方法我可以使用contourf

Or will I have to change my code to use imshow , which understands set_bad , instead of countourf ? 或将我不得不改变我的代码使用imshow ,这理解set_bad代替, countourf

Have you tried setting first the background, like: 您是否尝试过首先设置背景,例如:

x,y=meshgrid(linspace(0,1),linspace(0,1))
fig=plt.figure()
a=fig.add_subplot(111,axisbg='gray')
z=ma.masked_array(x**2-y**2,mask=y>-x+1)
a.contourf(z)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM