1.多個(gè)子圖繪制
#繪制多個(gè)子圖
#subplot(*args,**kwargs) 每個(gè)subplot函數(shù)只能繪制一個(gè)子圖
#subplots(nrows,ncols)
#fig_add_subplot(行,列,區(qū)域)
#繪制子圖第一種方式
plt.subplot(2,2,1)#第一個(gè)繪圖區(qū)域兩行兩列
#plt.subplot(221)簡寫方式
plt.plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)])
plt.subplot(2,2,2)#兩行兩列繪圖區(qū)的第二個(gè)繪圖區(qū)
plt.plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)],'ro')
plt.subplot(2,1,2)#兩行一列 ,第二行繪制
x=[1,2,3,4,5]
y=[random.randint(10,50) for i in range(5)]
plt.bar(x,y)
plt.show()
#繪制的第二種方式
#兩行三列的畫圖區(qū)域
#figure畫布,axes坐標(biāo)軸對象
figure,axes=plt.subplots(2,3)
plt.show()
figure,axes=plt.subplots(2,2)
axes[0,0].plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)])
axes[0,1].plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)],'ro')
x=[1,2,3,4,5]
y=[random.randint(10,50) for i in range(5)]
axes[1,0].bar(x,y)
x=[random.randint(10,50) for i in range(5)]
axes[1,1].pie(x,autopct='%1.1f%%')
plt.show()
#繪制子圖的第三種方式
#繪制畫布
fig=plt.figure()
ax1=fig.add_subplot(2,2,1) #兩行兩列第一個(gè)繪圖區(qū)域
ax1.plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)])
ax2=fig.add_subplot(2,2,2) #兩行兩列第二個(gè)繪圖區(qū)域
ax2.plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)],'ro')
ax3=fig.add_subplot(2,2,3)
ax3.bar([1,2,3,4,5],[random.randint(1,10) for i in range(5)])
ax4=fig.add_subplot(2,2,4)
ax4.pie([random.randint(1,10) for i in range(5)],autopct='%1.1f%%')
plt.show()
2.
#圖表的保存
#圖表保存格式j(luò)peg,tiff,png
#plt.savefig(圖名)
3.seaborn使用,首先安裝。如果在pycharm中安裝報(bào)錯(cuò),先安裝Scipy
import matplotlib.pyplot as plt
import seaborn as sns
#seaborn繪圖
#繪制簡單柱狀圖
sns.set_style('darkgrid')#設(shè)置風(fēng)格樣式
x=[1,2,3,4,5]
y=[20,6,50,9,56]
sns.barplot(x,y)
plt.show()
文章來源:http://www.zghlxwxcb.cn/news/detail-635978.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-635978.html
到了這里,關(guān)于數(shù)據(jù)可視化(六)多個(gè)子圖及seaborn使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!