網站首頁 編程語言 正文
python的annotate函數
annotate函數
該函數的詳細參數可調用內置屬性__doc__查看。
import matplotlib.pyplot as plt # plt.annotate(str, xy=data_point_position, xytext=annotate_position, # va="center", ha="center", xycoords="axes fraction", # textcoords="axes fraction", bbox=annotate_box_type, arrowprops=arrow_style) # str是給數據點添加注釋的內容,支持輸入一個字符串 # xy=是要添加注釋的數據點的位置 # xytext=是注釋內容的位置 # bbox=是注釋框的風格和顏色深度,fc越小,注釋框的顏色越深,支持輸入一個字典 # va="center", ha="center"表示注釋的坐標以注釋框的正中心為準,而不是注釋框的左下角(v代表垂直方向,h代表水平方向) # xycoords和textcoords可以指定數據點的坐標系和注釋內容的坐標系,通常只需指定xycoords即可,textcoords默認和xycoords相同 # arrowprops可以指定箭頭的風格支持,輸入一個字典 # plt.annotate()的詳細參數可用__doc__查看,如:print(plt.annotate.__doc__)
例1:
import matplotlib.pyplot as plt fig = plt.figure(1, facecolor='white') fig.clf() plt.annotate('a decision node', (0.1, 0.5), (0.5, 0.1), va="center", ha="center", xycoords="axes fraction", textcoords="axes fraction", bbox=dict(boxstyle="sawtooth", fc="0.8"), arrowprops=dict(arrowstyle="<-")) plt.show()
結果如下:
例2:給注釋和數據點指定不同的坐標系
import matplotlib.pyplot as plt fig = plt.figure(1, facecolor='white') fig.clf() # 這里指定數據點的坐標系原點在xy軸的左下角,而注釋的坐標系原點在這個圖像(figure)的左下角 # 所以才會出現注釋內容下移覆蓋了x軸 plt.annotate('a decision node', (0.1, 0.5), (0.5, 0.1), va="center", ha="center", xycoords="axes fraction", textcoords="figure fraction", bbox=dict(boxstyle="sawtooth", fc="0.8"), arrowprops=dict(arrowstyle="<-")) plt.show()
結果如下:
可視化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()
原文鏈接:https://blog.csdn.net/watermelon12138/article/details/88375823
相關推薦
- 2022-05-24 C++實現路口交通燈模擬系統_C 語言
- 2022-07-31 Android項目開發常用工具類LightTaskUtils源碼介紹_Android
- 2022-08-12 Qt實現電子時鐘_C 語言
- 2022-11-21 Qt實現小功能之復雜抽屜效果詳解_C 語言
- 2022-11-08 python安裝包出現Retrying?(Retry(total=4,?connect=None,?
- 2022-08-23 React?中的列表渲染要加?key的原因分析_React
- 2022-05-13 linq中的限定操作符_實用技巧
- 2022-06-21 .net中常用的正則表達式_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支