在 Matplotlib 中在圓圈內放置文字


若要在 matplotlib 中在圓圈內放置文字,我們可以採取以下步驟 −

  • 使用 figure() 方法建立一個新圖形或啟用現有圖形。

  • 向當前軸新增一個子圖方法。

  • 使用Circle() 類建立圓形 例項。

  • 在繪圖中新增圓形 路徑。

  • 若要在圓圈中放置文字,我們可以使用 text() 方法。

  • 使用 xlim() ylim() 方法縮放 x 和 y 軸。

  • 若要顯示圖形,請使用 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()

輸出

更新日期:12-5-2021

2K+ 瀏覽量

開啟你的 職業生涯

透過完成課程獲取認證

開始
廣告
© . All rights reserved.