Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中绘制多个子图数据帧直方图?_Python_Pandas_Matplotlib - Fatal编程技术网

如何在Python中绘制多个子图数据帧直方图?

如何在Python中绘制多个子图数据帧直方图?,python,pandas,matplotlib,Python,Pandas,Matplotlib,我尝试在4个子图中绘制四个数据帧列直方图,如下所示: fig2, ax2 = plt.subplots(nrows=2, ncols=2) ax2[0, 0] = completeDF['Number_of_Weeks_Used'].plot.hist(bins=100, alpha=0.8) ax2[0, 1] = completeDF['Season'].plot.hist(bins=100, alpha=0.8) 但它将两个图合并到一个子图中,如下所示: 轴的指定方式不正确 导入pa

我尝试在4个子图中绘制四个数据帧列直方图,如下所示:

fig2, ax2 = plt.subplots(nrows=2, ncols=2)
ax2[0, 0] = completeDF['Number_of_Weeks_Used'].plot.hist(bins=100, alpha=0.8)
ax2[0, 1] = completeDF['Season'].plot.hist(bins=100, alpha=0.8)
但它将两个图合并到一个子图中,如下所示:

  • 轴的指定方式不正确
导入pandas_datareader作为web#不是pandas的一部分;康达或pip安装
作为pd进口熊猫
导入matplotlib.pyplot
#获取测试数据
df=web.DataReader(“^gspc”,data_source='yahoo',start='2020-09-01',end='2020-09-28')。iloc[:,:4]
#固定数字
图,ax=plt.子批次(nrows=2,ncols=2,figsize=(8,8))
#绘制到不同的轴
df.High.plot.hist(存储单元=100,alpha=0.8,ax=ax[0,0])
df.Low.plot.hist(bin=100,alpha=0.8,ax=ax[0,1])
df.Open.plot.hist(bin=100,alpha=0.8,ax=ax[1,0])
df.Close.plot.hist(bin=100,alpha=0.8,ax=ax[1,1])
plt.紧_布局()
plt.show()

  • 以下,也将起作用
fig,((ax1,ax2),(ax3,ax4))=plt.子批(nrows=2,ncols=2,figsize=(8,8))
df.High.plot.hist(bin=100,alpha=0.8,ax=ax1,label='High')
df.Low.plot.hist(bin=100,alpha=0.8,ax=ax2,label='Low')
df.Open.plot.hist(bin=100,alpha=0.8,ax=ax3,label='Open')
df.Close.plot.hist(bin=100,alpha=0.8,ax=ax4,label='Close')