是否在Matplotlib中拟合圆面片溢出外部视图?

2024-05-07 06:55:11 发布

您现在位置:Python中文网/ 问答频道 /正文

import matplotlib
import numpy as np
from matplotlib.patches import Circle
import matplotlib.pyplot as plt
matplotlib.rcParams["figure.figsize"]=(6.4, 4.8)

fig, ax = plt.subplots()

circle1 = Circle((0.1, 0.1), 0.2, facecolor = "k", edgecolor = 'red', linewidth = 30)
circle2 = Circle((0.5, 0.5), 0.2, facecolor = "k")

ax.axis("equal")


ax.add_artist(circle1);
ax.add_artist(circle2);

plt.show()

当我运行上面的代码试图画两个圆时,补丁溢出到可见区域之外。我怎样才能使两个圆都进入视野?你知道吗


Tags: fromimportnumpyaddartistmatplotlibasnp
1条回答
网友
1楼 · 发布于 2024-05-07 06:55:11

首先,要向轴添加补丁,请使用ax.add_patch()
然后使用ax.autoscale()确保轴根据其内容进行缩放

ax.add_artist(circle1)
ax.add_artist(circle2)
ax.autoscale()

enter image description here

相关问题 更多 >