在 Matplotlib 中繪製帶有邊緣色和陰影的圓形


要在 matplotlib 中設定圓形的邊緣顏色和陰影,我們可以採取以下步驟 -

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

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

  • 使用具有edgecolorhatch和邊緣linewidthCircle() 類建立一個圓例項。

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

  • 要在圓內放置文字,請使用 text() 方法。

  • 使用 xlim()ylim() 方法縮放XY 軸。

  • 要顯示圖形,請使用 show() 方法。

示例

import matplotlib
from matplotlib import pyplot as plt, patches
plt.rcParams["figure.figsize"] = [7.50, 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=2, hatch="o")
ax.add_patch(circle)
plt.text(-.25, 0, "Circle")
plt.xlim([-4, 4])
plt.ylim([-4, 4])
plt.show()

輸出

更新日期:07-05-2021

408 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.