2016-04-05 280 views
0

我想在熊猫中创建一个有6个小区的图形,它是3x3。我正在根据数据框中的列进行绘图。大熊猫与熊猫

我想是这样的:

fig=plt.figure() 
ax1=fig.add_subplot(3,3,1) 
ax2=fig.add_subplot(3,3,2) 
ax3=fig.add_subplot(3,3,3) 
ax4=fig.add_subplot(3,3,4) 
ax5=fig.add_subplot(3,3,5) 
ax6=fig.add_subplot(3,3,6) 

ax1=df.plot(x='bnw_Value', y='bnw_Percent', title='BNW', kind='bar') 
ax1.set_xlabel('Value') 
ax1.set_ylabel('Percent') 
ax1.legend_.remove() 
ax1.set_yticks([0,5,10,20,25]) 
ax2=df.plot(x='php_Value', y='php_Percent', title='PHP', kind='bar') 
ax2.set_xlabel('Value') 
ax2.set_ylabel('Percent') 
ax2.legend_.remove() 
ax2.set_yticks([0,5,10,20,25]) 

,然后我做了其他四个地块,以及不同的X和Y值。

但这实际上并没有绘制到我的小区,而是绘制到个别地块。我怎么会真的阴谋到我在一开始创建的小区?

回答

3

你需要告诉df.plot()您要使用的插曲:

df.plot(x='bnw_Value', y='bnw_Percent', title='BNW', kind='bar', ax=ax1) 
df.plot(x='php_Value', y='php_Percent', title='PHP', kind='bar', ax=ax2) 

无需指定既然你已经有了返回的插曲对象的引用。