python可視化---annotate()函數


函數功能:添加圖形內容細節的指向型注釋文本。

調用簽名:plt.annotate(string, xy=(np.pi/2, 1.0), xytext=((np.pi/2)+0.15, 1,5), weight="bold", color="b", arrowprops=dict(arrowstyle="->", connectionstyle="arc3", color="b"))

string:圖形內容的注釋文本

xy:被注釋圖形內容的位置坐標

xytext:注釋文本的位置坐標

weight:注釋文本的字體粗細風格

color:注釋文本的字體顏色

arrowprops:指示被注釋內容的箭頭的屬性字典

代碼實現:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.05, 10, 1000)
y = np.sin(x)

plt.plot(x, y, ls="-.", lw=2, c="c", label="plot figure")

plt.legend()

plt.annotate("maximum", xy=(np.pi/2, 1.0), xytext=((np.pi/2)+1.0, .8),
             weight="bold", color="b", 
             arrowprops=dict(arrowstyle="->", connectionstyle="arc3", color="b"))

plt.show()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM