[英]Trying to plot 3 subplots with a shared x-axis
I'm trying to plot 3 subplots
with a shared x-axis but for some reason only one of my subplots
is plotting and I can't figure out why: 我正在尝试绘制具有共享x轴的3
subplots
,但是由于某些原因,我的一个subplots
正在绘制,而我不知道为什么:
df1 = pd.DataFrame({'col1':[1,2,3,None,5], 'col2':[25,5,None,None,1],
'col3':[40,3,None,None,None]}, index=[datetime.date(2015,7,7),datetime.date(2015,7,12),datetime.date(2015,8,1),datetime.date(2015,8,10),datetime.date(2015,9,20)])
df2 = pd.DataFrame({'col1':[14,82,None,None,1], 'col2':[5,5,None,4,1], 'col3':[4,3,5,None,6]},
index=[datetime.date(2015,7,10),datetime.date(2015,7,15),datetime.date(2015,8,4),datetime.date(2015,8,12),datetime.date(2015,9,25)])
df3 = pd.DataFrame({'col1':[10,9,None,None,15], 'col2':[None,5,None,3,1], 'col3':[None,3,3,1,74]},
index=[datetime.date(2015,7,5),datetime.date(2015,8,1),datetime.date(2015,8,9),datetime.date(2015,8,10),datetime.date(2015,9,20)])
fig=plt.figure(figsize=(15, 15))
ax1 = plt.subplot(313)
ax2 = plt.subplot(312, sharex = ax1)
ax3 = plt.subplot(311, sharex = ax1)
for column in df1.columns:
ax1 = plt.scatter(df1.index, df1[column], s=2)
for column in df2.columns:
ax2 = plt.scatter(df2.index, df2[column], s=2)
for column in df3.columns:
ax3 = plt.scatter(df3.index, df3[column], s=2)
plt.show()
You define subplots without using them. 您可以定义子图而不使用它们。 Use this:
用这个:
for column in df1.columns:
ax1.scatter(df1.index, df1[column], s=2)
for column in df2.columns:
ax2.scatter(df2.index, df2[column], s=2)
for column in df3.columns:
ax3.scatter(df3.index, df3[column], s=2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.