简体   繁体   中英

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".

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".

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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