如何利用 Matplotlib 在座標軸上簡單繪製雙箭頭?


想要利用 Matplotlib 在座標軸上繪製簡單的雙箭頭,可採取以下步驟 −

  • 設定圖形大小,調整子圖間和周圍的邊距。
  • 使用 annotate() 方法,用 text='Arrows' 標註點 xy。在元組開頭和結尾分別新增位置。在 arrowprops 詞典中,使用 arrowstyle "<->"color='red'
  • 利用 show() 方法顯示圖形。

示例

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

plt.annotate('Arrows', xy=(0.1, .1), xytext=(0.5, 0.5),
            arrowprops=dict(arrowstyle='<->', color='red'))

plt.show()

輸出

更新日期: 15-6-2021

3K+ 瀏覽量

開啟你的 事業

透過完成課程獲取認證

開始
廣告
© . All rights reserved.