简体   繁体   English

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

[英]Fit circle patch overflowing outside view in 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()

When I run the above code, which tries to draw 2 circles, the patches overflow outside the visible area. 当我运行上面的代码尝试绘制2个圆时,补丁在可见区域外溢出。 How can I fit both circles into view ? 如何使两个圆圈都适合观看?

First of all, to add a patch to an axes, use ax.add_patch() . 首先,要向轴添加补丁,请使用ax.add_patch()
Then to make sure the axes is scaled according to its content, use ax.autoscale() 然后,要确保根据其内容缩放轴,请使用ax.autoscale()

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM