在Matplotlib中适合圆补丁溢出外部视图吗?

时间:2018-12-22 20:10:36

标签: python matplotlib

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()

当我运行上面的代码尝试绘制2个圆时,补丁在可见区域之外溢出。如何使两个圆圈都适合观看?

1 个答案:

答案 0 :(得分:1)

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

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

enter image description here