简体   繁体   English

如何将每个月放在matplotlib的xaxis中?

[英]How to put each months in xaxis of matplotlib?

Let me ask a question that I asked before because it took a day. 让我问一个我之前问过的问题,因为它花了一天的时间。

I am trying to change the X axis of the axes from "2017-01" to "2017-12". 我正在尝试将轴的X轴从“ 2017-01”更改为“ 2017-12”。

But, I couldn't make it. 但是,我做不到。

Here is a dataset I use. 这是我使用的数据集。

在此处输入图片说明

在此处输入图片说明

The value of datetime is between "2017-01-01" to "2017-12-31". datetime的值在“ 2017-01-01”到“ 2017-12-31”之间。

Here is a code and outcome. 这是代码和结果。

df_for_extracting_song = df_daily[(df_daily["Artist"] == "Ed Sheeran") & (df_daily["Region"] == "global") & (df_daily["Position"] <= 100) & (df_daily["Date"] <= "2017-12-31")]
df_ed_sheeran = df_for_extracting_song.groupby(['Track Name']).size()
df_ed_sheeran = df_ed_sheeran.reset_index()
df_ed_sheeran = df_ed_sheeran[df_ed_sheeran[0] >= 20]
df_ed_sheeran = df_ed_sheeran.set_index("Track Name")
df_ed_sheeran = df_for_extracting_song[df_for_extracting_song['Track Name'].isin(df_ed_sheeran.index)]
df_ed_sheeran = df_ed_sheeran.reset_index()
plt.figure(figsize=(15,8))
ax = sns.scatterplot(x="Date", y="Position", data=df_ed_sheeran, hue="Track Name")
ax.invert_yaxis()
ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0, fontsize=18)

在此处输入图片说明

The problems are the xaxis of xaxes is different that I want and the outcome is at the right side. 问题是我想要的xaxes的xaxis不同,结果在右侧。

I have to get rid of it and set twelve months properly. 我必须摆脱它,并正确设置十二个月。

How can I make it? 我该怎么做?

I will appreciate it if you help me out. 如果您能帮助我,我将不胜感激。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM