在 Matplotlib 中使用邊框顏色繪製一個圓形


若要在 matplotlib 中繪製帶有邊框顏色的圓形,我們可以按照以下步驟操作 -

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

  • 向當前座標軸新增子圖方法。

  • 使用 **Circle()** 類建立 **circle** 例項,其中包含邊緣的 **edgecolor** 和 **linewidth**。

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

  • 若要在圓中放置文字,我們可以使用 **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, edgecolor="orange", linewidth=7)
ax.add_patch(circle)
plt.text(-.25, 0, "Circle")
plt.xlim([-4, 4])
plt.ylim([-4, 4])
plt.axis('equal')
plt.show()

輸出

更新於: 15-May-2021

2K+ 閱讀

開始你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.