美文网首页
subplots子画布

subplots子画布

作者: Chaweys | 来源:发表于2020-12-02 14:14 被阅读0次

#coding=utf-8
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#画折线图数据
x_data=[2011,2012,2013,2014,2015,2016,2017]
y_data=[58000,62000,63000,71000,84000,90500,107000]
y_data2=[52000,54200,51500,58300,56800,59500,62700]

#画条形图数据
bar_x=['a','b','c','d']
bar_y=[20,10,30,25]

#画直方图数据
s=np.random.randn(500)


#创建子画布
# figure,axes=plt.subplots()
'''
figure:代表画图
axes:   指定画子图位置
subplosts(nrows,nclos)参数:
nrows=1 默认为1
nclos=1 默认为1  代表创建一个画布
'''
#生成1个子画布
axes.plot(x_data,y_data)
plt.show()


#生成2个子画布
figure,axes=plt.subplots(nrows=1,ncols=2)
axes[0].plot(x_data,y_data)
axes[1].plot(x_data,y_data2)
plt.show()


#生成2x2的子画布
figure,axes=plt.subplots(nrows=2,ncols=2)
axes[0,0].plot(x_data,y_data)   #折线图
axes[0,1].plot(x_data,y_data2)  #折线图
axes[1,0].bar(bar_x,bar_y)      #条形图
axes[1,1].hist(s)               #直方图
plt.show()
subplots一个子画布画折线图.png
subplots二个子画布画折线图.png
subplots四个子画布画图.png

相关文章

网友评论

      本文标题:subplots子画布

      本文链接:https://www.haomeiwen.com/subject/lnlkwktx.html