您可以继承matplotlib.hatch.Shapes
并根据在单位平方[[-0.5,0.5] x [-0.5,0.5]]内绘制的任何参考路径定义自定义剖面线。
暂定:
import numpy as np
import matplotlib.hatch
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Polygon
house_path = Polygon(
[[-0.3, -0.4], [0.3, -0.4], [0.3, 0.1], [0., 0.4], [-0.3, 0.1]],
closed=True, fill=False).get_path()
class CustomHatch(matplotlib.hatch.Shapes):
"""
Custom hatches defined by a path drawn inside [-0.5, 0.5] square.
Identifier 'c'.
"""
filled = True
size = 1.0
path = house_path
def __init__(self, hatch, density):
self.num_rows = (hatch.count('c')) * density
self.shape_vertices = self.path.vertices
self.shape_codes = self.path.codes
matplotlib.hatch.Shapes.__init__(self, hatch, density)
matplotlib.hatch._hatch_types.append(CustomHatch)
fig = plt.figure()
ax = fig.add_subplot(111)
ellipse = ax.add_patch(Ellipse((0.5, 0.5), 0.3, 0.5, fill=False))
ellipse.set_hatch('c')
ellipse.set_color('red')
plt.show()
给予:
来源
2014-05-29 18:36:08
GBy
有的[定制舱口]的例子(http://stackoverflow.com/questions/4745937/how-to-decrease-孵化密度在matplotlib?rq = 1)在这里,但作者说这是脆弱的。 – cphlewis
标准set_hatch具有八个不同的孵化箱,每个孵箱都可以在至少两种密度下运行,并且可以进行组合。我想在你用完舱口组合之前,情节会让你感到困惑。您有几十个可用填充的灰度孵化示例吗? – cphlewis