Skip to content Skip to sidebar Skip to footer

Showing Index As Xticks For Pandas Plot

I have the following dataframe and am trying to plot it, so that it shows in the x-axis the index data from 8-19. If I do df.plot() no labels are shown at all. If I do df.plot(use_

Solution 1:

If you want to have string as xticks one possible solution is:

df = df.reset_index()
df = df.rename(columns={"index":"hour"})
ax = df.plot(xticks=df.index)
ax.set_xticklabels(df["hour"]);

Solution 2:

Until the bug in Pandas gets fixed, add this after df.plot(), no need for anything else:

plt.xticks(range(len(df.index)), df.index)

Solution 3:

Pandas version 0.24 for Python 3.6 (Windows) fixed this problem for me.


Post a Comment for "Showing Index As Xticks For Pandas Plot"