1. 程式人生 > >Python:給圖形中新增文字註釋(text函式)

Python:給圖形中新增文字註釋(text函式)

以下這個案例,基本上是我們平時註釋用的最多的,其基本思想就是,找到你想要註釋的那個位置,進行註釋,有的時候可以覺得用定死的方式來做,顯示出的效果也會很好。
平時可以多看看官網教程:text

#!/usr/bin/python
#coding: utf-8

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-10, 11, 1)  #形成一個數組,第三個引數表示步長,#start,end,step
y = x ** 2

plt.plot(x, y)

# 第一個引數是x軸座標
# 第二個引數是y軸座標
# 第三個引數是要顯式的內容
# alpha 設定字型的透明度 # family 設定字型 # size 設定字型的大小 # style 設定字型的風格 # wight 字型的粗細 # bbox 給字型新增框,alpha 設定框體的透明度, facecolor 設定框體的顏色 plt.text(-3, 20, "function: y = x * x", size = 15, alpha = 0.2) plt.text(-3, 40, "function: y = x * x", size = 15,\ family = "fantasy", color = "r", style = "italic", weight = "light"
,\ bbox = dict(facecolor = "r", alpha = 0.2)) plt.show()

這裡寫圖片描述