gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:56:38 26 4
gpt4 key购买 nike

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

最佳答案

Arc 类型是 Ellipse 的子类,经过扩展可添加两个值 theta1theta2angle 的行为对于 EllipseArc 是相同的,并确定绘制椭圆的角度。

from matplotlib import pyplot as plt
from matplotlib.patches import Ellipse

fig = plt.figure(figsize=(2,5))
ax = fig.add_subplot(1,1,1)
ax.set_ylim(0, 50)
ax.set_xlim(0, 20)
ax.axis('off')

a = Ellipse((10, 45), 10, 3, 0, color='red', lw=1)
ax.add_patch(a)

a = Ellipse((10, 40), 10, 3, 10, color='red', lw=1)
ax.add_patch(a)

a = Ellipse((10, 35), 10, 3, 20, color='red', lw=1)
ax.add_patch(a)

a = Ellipse((10, 30), 10, 3, 30, color='red', lw=1)
ax.add_patch(a)

for a in range(0, 360, 40):
a = Ellipse((10, 20), 10, 3, a, color='red', lw=1, fc='none')
ax.add_patch(a)

这会产生 -

elliipse rotation

请注意,对于完美的圆形(高度宽度相等的椭圆),这没有什么区别(因为圆是旋转对称的)。

from matplotlib import pyplot as plt
from matplotlib.patches import Ellipse

fig = plt.figure(figsize=(2,4))
ax = fig.add_subplot(1,1,1)
ax.set_ylim(0, 40)
ax.set_xlim(0, 20)
ax.axis('off')

a = Ellipse((10, 25), 10, 10, 0, color='red', lw=1)
ax.add_patch(a)

a = Ellipse((10, 10), 10, 10, 45, color='red', lw=1)
ax.add_patch(a)

两个圆是相同的。

rotation of a circle

Arc documentation对于 matplotlib.patches.Arc 解释说 theta 1 和 2 是 -

theta1, theta2 : float, optional

Starting and ending angles of the arc in degrees. These values are relative to angle, .e.g. if angle = 45 and theta1 = 90 the absolute starting angle is 135. Default theta1 = 0, theta2 = 360, i.e. a complete ellipse.

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

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

from matplotlib import pyplot as plt
from matplotlib.patches import Arc

fig = plt.figure(figsize=(2,5))
ax = fig.add_subplot(1,1,1)
ax.set_ylim(0, 50)
ax.set_xlim(0, 20)
ax.axis('off')

# A complete ellipse, using theta1=0, theta2=360.
a = Arc((10, 45), 10, 3, 0, 0, 360, color='red', lw=1)
ax.add_patch(a)

# Reduce theta2 to 350, last 10 deg of ellipse not drawn.
a = Arc((10, 40), 10, 3, 0, 0, 350, color='red', lw=1)
ax.add_patch(a)

# Rotate the ellipse (angle=90), theta1 & theta2 are relative to start angle & rotate too.
a = Arc((10, 30), 10, 3, 90, 0, 350, color='red', lw=1)
ax.add_patch(a)

# Rotate the ellipse (angle=180), as above.
a = Arc((10, 20), 10, 3, 180, 0, 350, color='red', lw=1)
ax.add_patch(a)

# Draw the top half of the ellipse (theta 0-180 deg).
a = Arc((10, 10), 10, 3, 0, 0, 180, color='red', lw=1)
ax.add_patch(a)

# Draw the bottom half of the ellipse (theta 180-360 deg).
a = Arc((10, 5), 10, 3, 0, 180, 360, color='red', lw=1)
ax.add_patch(a)

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

theta 1 and theta2 Arc examples

关于python-3.x - 有人可以解释 matplotlib.patches.arc 中的不同参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54849976/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com