有人可以解释 matplotlib.patches.arc 中的不同参数吗?

Abh*_*hek 2 matplotlib python-3.x

我只想了解基本参数以及它们的具体作用 - 宽度、高度、角度、theta1、theta 2。我按照官方文档,了解了中心是什么,但我不明白 theta 1 或 2 是什么是什么,或者角度是什么,或者水平轴或垂直轴的长度意味着什么。我尝试使用不同的数字来试验参数,但未能得出准确的结果。我试图在篮球场上创建三分球区的弧线

mfi*_*tzp 5

该Arc类型是 的子类Ellipse,扩展为添加两个值theta1和theta2。和的行为angle相同,并且确定绘制椭圆的角度。EllipseArc

\n\n
from matplotlib import pyplot as plt\nfrom matplotlib.patches import Ellipse\n\nfig = plt.figure(figsize=(2,5))\nax = fig.add_subplot(1,1,1)\nax.set_ylim(0, 50)\nax.set_xlim(0, 20)\nax.axis(\'off\')\n\na = Ellipse((10, 45), 10, 3, 0, color=\'red\', lw=1)\nax.add_patch(a)\n\na = Ellipse((10, 40), 10, 3, 10, color=\'red\', lw=1)\nax.add_patch(a)\n\na = Ellipse((10, 35), 10, 3, 20, color=\'red\', lw=1)\nax.add_patch(a)\n\na = Ellipse((10, 30), 10, 3, 30, color=\'red\', lw=1)\nax.add_patch(a)\n\nfor a in range(0, 360, 40):\n    a = Ellipse((10, 20), 10, 3, a, color=\'red\', lw=1, fc=\'none\')\n    ax.add_patch(a)\n
Run Code Online (Sandbox Code Playgroud)\n\n

这会产生 \xe2\x80\x94

\n\n

椭圆旋转

\n\n

height请注意,对于完美的圆(等于和的椭圆width),这没有区别(因为圆是旋转对称的)。

\n\n
from matplotlib import pyplot as plt\nfrom matplotlib.patches import Ellipse\n\nfig = plt.figure(figsize=(2,4))\nax = fig.add_subplot(1,1,1)\nax.set_ylim(0, 40)\nax.set_xlim(0, 20)\nax.axis(\'off\')\n\na = Ellipse((10, 25), 10, 10, 0, color=\'red\', lw=1)\nax.add_patch(a)\n\na = Ellipse((10, 10), 10, 10, 45, color=\'red\', lw=1)\nax.add_patch(a)\n
Run Code Online (Sandbox Code Playgroud)\n\n

两个圆都是一样的。

\n\n

圆的旋转

\n\n

Arc文档解释matplotlib.patches.Arc了 theta 1 和 2 是 \xe2\x80\x94

\n\n
\n

theta1,theta2:float, 选修的

\n\n

弧的起始角和结束角(以度为单位)。这些值是相对于角度的,例如,如果角度 = 45 且 theta1 = 90,则绝对起始角度为 135。默认 theta1 = 0,theta2 = 360,即完整的椭圆形。

\n
\n\n

其中的关键语句是“默认 theta1 = 0,theta2 = 360,即完整的椭圆”。\xe2\x80\x94\xc2\xa0这些参数用于绘制部分椭圆,以创建圆弧。theta1是椭圆开始绘制的角度(或位置) ,theta2是停止绘制的时间。请注意,椭圆的计算不受影响。

\n\n

下面的代码绘制了一系列的弧线,这应该使逻辑变得明显 \xe2\x80\x94

\n\n
from matplotlib import pyplot as plt\nfrom matplotlib.patches import Arc\n\nfig = plt.figure(figsize=(2,5))\nax = fig.add_subplot(1,1,1)\nax.set_ylim(0, 50)\nax.set_xlim(0, 20)\nax.axis(\'off\')\n\n#\xc2\xa0A complete ellipse, using theta1=0, theta2=360.\na = Arc((10, 45), 10, 3, 0, 0, 360, color=\'red\', lw=1)\nax.add_patch(a)\n\n#\xc2\xa0Reduce theta2 to 350, last 10 deg of ellipse not drawn.\na = Arc((10, 40), 10, 3, 0, 0, 350, color=\'red\', lw=1)\nax.add_patch(a)\n\n# Rotate the ellipse (angle=90), theta1 & theta2 are relative to start angle & rotate too.\na = Arc((10, 30), 10, 3, 90, 0, 350, color=\'red\', lw=1)\nax.add_patch(a)\n\n# Rotate the ellipse (angle=180), as above.\na = Arc((10, 20), 10, 3, 180, 0, 350, color=\'red\', lw=1)\nax.add_patch(a)\n\n# Draw the top half of the ellipse (theta 0-180 deg). \na = Arc((10, 10), 10, 3, 0, 0, 180, color=\'red\', lw=1)\nax.add_patch(a)\n\n# Draw the bottom half of the ellipse (theta 180-360 deg).\na = Arc((10, 5), 10, 3, 0, 180, 360, color=\'red\', lw=1)\nax.add_patch(a)\n
Run Code Online (Sandbox Code Playgroud)\n\n

这会产生以下图像,上面绘制了从上到下的弧线。对照代码中的注释进行解释。

\n\n

theta 1 和 theta2 弧形示例

\n