绘图:如何分隔XTICK?

2024-04-27 10:06:39 发布

您现在位置:Python中文网/ 问答频道 /正文

聚合后,我绘制了数字,但我很难将XTICK隔开

聚集

tweet['Retweets']=pd.to_numeric(tweet['Retweets'])
tweet['Favorites']=pd.to_numeric(tweet['Favorites'])
sum_df = tweet.groupby(['Realdate'], as_index=False).agg({'Retweets': 'sum', 'Favorites': 'sum'})
sum_df=sum_df.reset_index()

策划

fig, ax1 = plt.subplots(figsize=(15, 10))
ax2 = ax1.twinx()
ax1.set_xlabel('Dates')
ax1.set_ylabel('Favorites', color='b')
ax2.set_ylabel('Retweets', color='b')
ax1.yaxis.tick_right()
ax2.yaxis.tick_left()
sum_df['Favorites'].plot( kind='bar', color='y', ax=ax1) 
sum_df['Retweets'].plot( kind='line', marker='d', ax=ax2)
ax1.legend(loc=2) # is this the right thing to do to place legends?
ax2.legend(loc=1) # is this the right thing to do to place legends?
ax1.set_xticklabels(sum_df.Realdate.values, rotation=90)
plt.title('Sum of Daily "Likes" and Retweets Time Series')
plt.show()

结果输出

enter image description here

你能帮我处理一下这个问题吗?我尝试了几种方法,但没有结果

非常感谢


Tags: torightdfplttweetcolorpdsum