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

时间:2013-06-11 11:25:47

标签: python matplotlib contour

当我使用matplotlib countourf绘制具有蒙版值的数组时,蒙版值显示为白色。我希望它们显得灰色。

我尝试了set_bad方法,但似乎countourf无法识别它(尽管它识别set_overset_under方法)。

我可以使用contourf吗?

或者我是否必须更改我的代码才能使用imshow,而set_bad代替countourf

1 个答案:

答案 0 :(得分:6)

您是否尝试过首先设置背景,例如:

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)