matplotlib中没有边缘的阴影矩形补丁 [英] hatched rectangle patches without edges in matplotlib

查看:48
本文介绍了matplotlib中没有边缘的阴影矩形补丁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试向绘图添加带有填充图案的矩形块时,似乎不可能在指定填充值时将关键字参数 edgecolor 设置为none".换句话说,我正在尝试添加一个阴影矩形,不带边但填充图案.这似乎不起作用.仅当我还允许在矩形块周围绘制边缘时,才会显示该图案.

When trying to add a rectangle patch with a hatch pattern to a plot it seems that it is impossible to set the keyword argument edgecolor to 'none' when also specifying a hatch value. In other words I am trying to add a hatched rectangle WITHOUT an edge but WITH a pattern filling. This doesnt seem to work. The pattern only shows up if I also allow an edge to be drawn around the rectangle patch.

任何有关如何实现所需行为的帮助吗?

Any help on how to achieve the desired behaviour?

推荐答案

您应该使用 linewidth 参数,该参数必须设置为零.

You should use the linewidth argument, which has to be set to zero.

示例(基于您的其他问题答案):

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np

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

# generate some data:
x,y = np.meshgrid(np.linspace(0,1),np.linspace(0,1))
z = np.ma.masked_array(x**2-y**2,mask=y>-x+1)

# plot your masked array
ax.contourf(z)

# plot a patch
p = patches.Rectangle((20,20), 20, 20, linewidth=0, fill=None, hatch='///')
ax.add_patch(p)
plt.show()

你会得到这张图片:

这篇关于matplotlib中没有边缘的阴影矩形补丁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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