數據可視化基礎(六):註釋、文字、tex公式、工具欄

註釋+箭頭

函數參數

annotate(‘註釋文字’,xy=(註釋形狀起始點座標),xytext=(註釋起始點座標),arrowprops=dict())
arrowprops

  • facecolor 顏色
  • frac 箭頭佔整個長度的比例 爲1是三角形
  • headwidth 箭頭寬度
  • width 箭身長

代碼

import matplotlib.pyplot as plt
import numpy as np

#註釋
x=np.arange(-10,11,1)
y=x*x

plt.plot(x,y)

plt.annotate('this',xy=(0,1),xytext=(0,20),
             arrowprops=dict(facecolor='r',frac=0.3,headwidth=20,width=5))
plt.show()

在這裏插入圖片描述

文字

函數參數

plt.text(起始橫座標,起始縱座標,‘文字內容’,family=‘字體’,size=大小數值,color=‘顏色’,style=‘是否斜體’,weight=粗細)

  • family 字體 ‘serif’ ‘sans=serif’ ‘cursive’ ‘fantasy’等
  • style 樣式 normal ;size=20,color=‘r’,style= oblique 斜體
  • weight 數字0-100/文字
    ultralight , light , normal , regular , book , medium , roman , semibold , demibold , demi , bold , heavy , extra bold , black

bbox=dict(facecolor=‘顏色’,alpha=透明度<1) 文字框體

代碼

import matplotlib.pyplot as plt
import numpy as np

# 文字
x=np.arange(-10,11,1)
y=x*x

plt.text(-2,40,'function word',family='fantasy',size=20,color='r',style='italic',weight='black',bbox=dict(facecolor='magenta',alpha=0.2))

plt.text(-2,20,'function word')

plt.plot(x, y)
plt.show()

在這裏插入圖片描述

Tex公式

概念

自帶mathtext引擎,不需要安裝TeX系統
$作爲開始和結束

函數參數

text(橫,縱, r" “不轉義

  • 特殊字符
    r"$\alpha \beta \pi \lambda \omega $"
    在這裏插入圖片描述

  • 下標
    _字母數字

  • 分數
    \frac{分子}{分母}

  • 極限 趨近於
    lim_{x \rightarrow y}

  • 根號
    \sqrt[幾次方]{開哪個參數}

代碼

import matplotlib.pyplot as plt
import numpy as np

# tex公式
fig=plt.figure()
ax=fig.add_subplot(111)

ax.set_xlim([1,7])
ax.set_ylim([1,5])

ax.text(2,4,r"$\alpha_i \beta_j \pi_k \lambda \omega $",size=20)

ax.text(4,4,r"$ sin(0)=cos(\frac{\pi}{2})$",size=20)

ax.text(2,2,r"$ \lim_{x \rightarrow y} \frac{1}{x^3} $",size=20)

ax.text(4,2,r"$ \sqrt[4]{x} = \sqrt{y}$",size=20)

plt.show()

在這裏插入圖片描述

工具欄

調試——放大縮小保存查看

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章