Tobi
Tobi

Reputation: 1902

Not shown x-axis labels in matplotlib subplots from pandas dataframe

I try to print out subplots. Sadly just the last of those plots has x axis labels / dates shown. How can I show the date below each graph.

It looks like this, but I wan't x axis for all graphs

enter image description here

import matplotlib.pyplot as plt

axes = dfDiscoverNerPivot.plot.line(x="date",subplots=True, legend=True, fontsize=8, grid=False, figsize=(10,25), linewidth=3)
plt.xticks(rotation=90)

for ax in axes.flatten():
    ax.axhline(5000, color='k', linestyle='--')
    ax.legend(loc='upper center')

plt.show()

I'm using google colab and pandas.

Upvotes: 1

Views: 1980

Answers (1)

You have subplots=True and all subplots are sharing the same x-axis. Passing in sharex=False in the plot.line method should do the trick.

You can pass in keyword arguments into DataFrame.plot.line which are passed onto DataFrame.plot. You can check them out in the docs.

Upvotes: 2

Related Questions