在 Matplotlib 中将文本放在圆圈内
matplotlibpythondata visualization更新于 2025/4/18 13:00:17
要在 matplotlib 中将文本放在圆圈内,我们可以采取以下步骤 −
使用 figure() 方法创建新图形或激活现有图形。
向当前轴添加子图方法。
使用 Circle() 类创建 Circle 实例。
在绘图上添加 circle 路径。
要将文本放在圆圈中,我们可以使用 text() 方法。
缩放 x 和 y 轴使用 xlim() 和 ylim() 方法。
要显示图形,请使用 show()方法。
示例
import matplotlib
from matplotlib import pyplot as plt, patches
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot(111)
circle = matplotlib.patches.Circle((0, 0), radius=1, color='yellow')
ax.add_patch(circle)
plt.text(-.25, 0, "This is a Circle")
plt.xlim([-4, 4])
plt.ylim([-4, 4])
plt.axis('equal')
plt.show()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

