我有几个添加了轴的散点图(对输出进行颜色编码),我想将它们放在矩阵中(子图)。但是,由于它们已经被砍掉了,我得到错误:TypeError: inner() got multiple values for keyword argument 'ax'
,正如预期的那样,我得到4x2空图,而其他图只是在它下面。告诉你我的意思:
fig1, axes1 = plt.subplots(nrows=4, ncols=2)
scatter1 = df.groupby(['Month', 'Price'])['Quantity'].sum().reset_index()
ax = scatter1[scatter1['Price'] == 460].plot(kind='scatter', x='Month', y='Quantity', color='Blue', label='230HUF');
fig1 = scatter1[scatter1['Price'] == 500].plot(kind='scatter', x = 'Month', y = 'Quantity', color='Yellow', label='250HUF', ax = ax )
scatter2 = df.groupby(['Month', 'Price'])['Quantity'].sum().reset_index()
ax = scatter2[scatter2['Price'] == 460].plot(kind='scatter', x='Month', y='Quantity', color='Blue', label='230HUF');
fig2 = scatter2[scatter2['Price'] == 500].plot(kind='scatter', x = 'Month', y = 'Quantity', color='Yellow', label='250HUF', ax = ax )
fig1.plot(figsize = (25,20),ax=axes1[0,0])
fig2.plot(figsize = (25,20),ax=axes1[0,1])
显示了这一点:
我想要实现的目标:
谢谢!
答案 0 :(得分:1)
您需要将ax=axes1[0]
参数添加到第一个df.plot
调用,ax=axes1[1]
添加到第二个,等等。
编辑:
您想要做的事情应该是这样的:
创建一些模拟数据帧:
df1=pd.DataFrame(rand(10,2),columns=['x column','y column'])
df2=pd.DataFrame(rand(10,2),columns=['x column','y column'])
df3=pd.DataFrame(rand(10,2),columns=['x column','y column'])
df4=pd.DataFrame(rand(10,2),columns=['x column','y column'])
创建图表:
fig,axes=plt.subplots(nrows=2,ncols=2)
df1.plot(kind='scatter',x='x column',y='y column',ax=axes[0,0])
df2.plot(kind='scatter',x='x column',y='y column',ax=axes[0,1],color='red')
df3.plot(kind='scatter',x='x column',y='y column',ax=axes[1,0],color='green')
df1.plot(kind='scatter',x='x column',y='y column',ax=axes[1,1],color='orange')
这导致了这个情节: