在matplotlib中,我想画一个填充的弧线,如下所示:
以下代码导致未填充的直线弧:
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
fg, ax = plt.subplots(1, 1)
pac = mpatches.Arc([0, -2.5], 5, 5, angle=0, theta1=45, theta2=135)
ax.add_patch(pac)
ax.axis([-2, 2, -2, 2])
ax.set_aspect("equal")
fg.canvas.draw()
documentation表示填充弧是不可能的。 画一张最好的方法是什么?
您可以使用
fill_between
来实现这一点用r和yoff来移动弧
编辑:
好吧,你想画出任意角度?你只需要找到和弦的方程,而不是像上面那样使用一条平线。这里有一个函数可以做到这一点:
结果如下:
可以绘制一个楔块,然后用三角形隐藏其中的一部分:
然后你可以称之为:
你会得到:
或:
你会得到:
高温高压
@jeanrjc's solution几乎可以让您到达目的地,但它添加了一个完全不必要的白色三角形,这也将隐藏其他对象(参见下图,版本1)。
这是一种更简单的方法,仅添加弧的多边形:
基本上,我们沿着圆的边缘(从
theta1
到theta2
)创建一系列点(points
)。这已经足够了,因为我们可以在Polygon
构造函数中设置close
标志,该标志将从最后一点添加到第一点(创建闭合弧)。然后我们应用它:
结果(版本2):
相关问题 更多 >
编程相关推荐