以下内容不能解决此问题。它只是解决了问题的一部分,并显示了该方法在哪一点上失败。我目前确信matplotlib无法使用任意角度进行图案填充,因为单位单元格的大小是固定的。
为了克服设置角度的问题,可以定义一个自定义格式,从中获取角度信息。E、 g."{angle}{factor}",使得{}将产生45°角和密度因子2的阴影。在
然后我不完全理解计算顶点的尝试。为了复制内置舱口的行为,可以直接旋转舱口。在
问题是,这种方法只能对45°的角度进行线填充。这是因为单位单元格边缘的线条没有很好地对齐。请参见以下内容:import numpy as np
import matplotlib.hatch
import matplotlib.path
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Rectangle
class AngularHatch(matplotlib.hatch.HatchPatternBase):
def __init__(self, hatch, density):
self.num_lines=0
self.num_vertices=0
if hatch[0] == "{":
h = hatch.strip("{}").split("}{")
angle = np.deg2rad(float(h[0])-45)
d = float(h[1])
self.num_lines = int(density*d)
self.num_vertices =