Python之pyplot 資料視覺化

2021-10-01 04:06:08 字數 2251 閱讀 7532

先導入pyplot

import matplotlib.pyplot as plt
#生成0~25之間均分的40個數

x = np.linspace(0,

25,40)

y = np.copy(x)

#將y打亂

np.random.shuffle(y)

print

('x: '

,end='')

print

(x)print

('y: '

,end='')

print

(y)

#列印折線圖,橫座標為x,縱座標為y

plt.plot(x,y)

#給x,y軸命名

plt.xlabel(

'this is x'

)plt.ylabel(

'this is y'

)#給折線圖命名

#生成需要的資料

x1 = np.linspace(0,

50,5)

x2 = np.sort(

50* np.random.rand(5)

)x3 = np.sort(

50* np.random.ranf(5)

)y = np.copy(x1)

np.random.shuffle(y)

#將多個折線圖一起列印

#label是給每條折線乙個名稱

plt.plot(x1,y,c=

'blue'

,label=

'i love x1'

)plt.plot(x2,y,c=

'green'

,label=

'hello'

)plt.plot(x3,y,c=

'red'

,label=

'x3'

)#列印座標軸的名稱

plt.xlabel(

'this is x'

)plt.ylabel(

'this is y'

)#列印折線圖的名稱

(1)建立乙個尺寸為5x5的圖

fig = plt.figure(figsize=(5

,5))

(2)將建立的圖分割成2行3列(共6個)的子圖,並在其1,5,6的子圖中列印出折線圖

#子圖位置分布為1,5,6

Python資料之configparser模組

configparser用於處理特定格式的檔案,其本質上是利用open來操作檔案。檔案格式 test.config 注釋1 注釋2 section1 節點 k1 v1 值 k2 v2 值 section2 節點 k1 v1 值 讀資料 import configparser config confi...

python之request post資料的方法

參考 今天學習一下request的幾種post方式 一 以data的形式post import requests defmain post data url response requests.post url,data post data print response response 200 說...

python之資料型別

python3 中有六個標準的資料型別 python3 支援int float bool complex 複數 在python 3裡,只有一種整數型別 int,表示為長整型,沒有 python2 中的 long。tuple 元組 元組 tuple 與列表類似,不同之處在於元組的元素不能修改。元組寫在...