matplotlib視覺化(一)

2021-09-24 19:03:26 字數 1247 閱讀 7617

關於figure

乙個figure代表乙個視窗,可以有多個figure,乙個figure下可有多個圖形

1.多個視窗

import numpy as np

import matplotlib.pyplot as plt

x=np.linspace(-3,3,50)

y1=2*x+1

y2=x**2

plt.figure() //第乙個figure

plt.plot(x,y1)

plt.figure(num=3,figsize=(8,5)) //第二個figure,可以設定編號,視窗大小

plt.plot(x,y2)

plt.plot(x,y1,color='r',linewidth=1.0,linestyle='--')

plt.show()

2.乙個視窗下有多個圖表

方法一:

import numpy as np

import matplotlib.pyplot as plt

plt.figure()

plt.subplot(2,1,1)

plt.plot([0,1],[0,1])

plt.subplot(2,3,4)

plt.plot([0,1],[0,2])

plt.subplot(2,3,5)

plt.plot([0,1],[0,3])

plt.subplot(2,3,6)

plt.plot([0,1],[0,4])

plt.show()

方法二:

gs=gridspec.gridspec(3,3)

ax1=plt.subplot(gs[0,:])

ax2=plt.subplot(gs[1,:2])

ax3=plt.subplot(gs[1:,2])

ax4=plt.subplot(gs[-1,0])

ax5=plt.subplot(gs[-1,-2])

方法三:

f,((ax11,ax12),(ax21,ax22))=plt.subplots(2,2,sharex=true,sharey=true)

ax11.scatter([1,2],[1,2])

plt.tight_layout()

plt.show()```

Matplotlib 資料視覺化

資料視覺化,更有意義的說法是,data communication for audiences。matplotlib總是因為它的aesthetics和amounts of codes被些許詬病。然而,我覺得熟練的使用之後,它的靈活性還是比較強的 相比ggplot 所以這篇文章的適合讀者是 具體的實現...

資料視覺化 matplotlib

直方圖plt.hist 資料,分組數,density true 複製 條形圖plt.bar x,y,color 顏色 plt.barh 複製 散點圖plt.scatter x,y 複製 折線圖 繪製多個圖形,多次plot plt.plot x,y,label 標籤 複製 通用操作plt.figure...

Python視覺化庫matplotlib

matplotlib matplotlib 是經典老牌的python資料視覺化庫了。在python社群裡幾乎無人不知。而且它模仿了1980年代的matlab視覺化庫。又因為matplotlib是第乙個python資料視覺化庫,許多優秀的視覺化庫是基於matplotlib的,比如 pandas 和 s...