Python 中的补丁是什么?
What are patches in Python?
我目前正在尝试在 Python 中画一个圆圈。然而,圆圈的轮廓并不是在绘制。我尝试更改线型,但出现错误。
查看 Circle documentation 上的有效 kwargs 列表 – linestyle
可以是 solid
、dashed
、dashdot
或 [=15] 之一=].
circ = plt.Circle((x,y), R, linestyle='dashed', edgecolor='b', facecolor='none')
线型不一致正在整理中(https://github.com/matplotlib/matplotlib/pull/3772)。
mpl 架构的快速总结:Figure
s 有 1 个或多个 Axes
,其中有许多 Artist
s(细微的细节,Axes
和 Figure
实际上是 Artist
的子 类,并且 Figure
对象除了 Axes
之外还可以有其他 Artist
)。 Figure
个对象也有一个 Canvas
个对象(其中有许多输出为不同格式的实现(例如 png、tiff、svg、pdf、eps、...)。当你绘制 Figure
有一些内部管道,每个 Artist
对象都递归绘制到 Canvas
。
大多数 plt
命令会创建一个 Artist
,然后将其添加到您当前的 Axes
(它 pyplot
有足够的内部状态来了解您当前的 Axes
是并在需要时创建一个)。但是,Circle
只是创建 return 一个 Patch
对象(这是 Artist
的一种类型)。 Circle
直接通过 pyplot
接口暴露出来有些奇怪。
要实现此功能,您需要执行类似
的操作
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
fig, ax = plt.subplots()
# note use Circle directly from patches
circ = mpatches.Circle((1, 0), 5, linestyle='solid', edgecolor='b', facecolor='none')
ax.add_patch(circ)
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)
ax.set_aspect('equal')
请关注PEP8,稍后你会感谢你自己。
我目前正在尝试在 Python 中画一个圆圈。然而,圆圈的轮廓并不是在绘制。我尝试更改线型,但出现错误。
查看 Circle documentation 上的有效 kwargs 列表 – linestyle
可以是 solid
、dashed
、dashdot
或 [=15] 之一=].
circ = plt.Circle((x,y), R, linestyle='dashed', edgecolor='b', facecolor='none')
线型不一致正在整理中(https://github.com/matplotlib/matplotlib/pull/3772)。
mpl 架构的快速总结:Figure
s 有 1 个或多个 Axes
,其中有许多 Artist
s(细微的细节,Axes
和 Figure
实际上是 Artist
的子 类,并且 Figure
对象除了 Axes
之外还可以有其他 Artist
)。 Figure
个对象也有一个 Canvas
个对象(其中有许多输出为不同格式的实现(例如 png、tiff、svg、pdf、eps、...)。当你绘制 Figure
有一些内部管道,每个 Artist
对象都递归绘制到 Canvas
。
大多数 plt
命令会创建一个 Artist
,然后将其添加到您当前的 Axes
(它 pyplot
有足够的内部状态来了解您当前的 Axes
是并在需要时创建一个)。但是,Circle
只是创建 return 一个 Patch
对象(这是 Artist
的一种类型)。 Circle
直接通过 pyplot
接口暴露出来有些奇怪。
要实现此功能,您需要执行类似
的操作import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
fig, ax = plt.subplots()
# note use Circle directly from patches
circ = mpatches.Circle((1, 0), 5, linestyle='solid', edgecolor='b', facecolor='none')
ax.add_patch(circ)
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)
ax.set_aspect('equal')
请关注PEP8,稍后你会感谢你自己。