Chris
Chris

Reputation: 13660

Pandas skipping x tick labels

I have a plot with 15 axis labels and Pandas automatically defaults to showing every other category name. How do I get it to show ALL of the x-axis labels without skipping items?

rows = []
for x in range(0,14):
    rows.append(['a',14-x])

df = pd.DataFrame(rows)
df = df.set_index(0)
df.plot(xticks=df.index)

Upvotes: 2

Views: 6030

Answers (1)

Julien Spronck
Julien Spronck

Reputation: 15423

You can define the axes first, create your plot using the keyword ax and set the ticks and tick labels manually using ax.set_xticks() (http://matplotlib.org/api/axes_api.html):

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)

rows = []
for x in range(0,14):
    rows.append(['a',14-x])

df = pd.DataFrame(rows)
# df = df.set_index(0)
df.plot(ax=ax)

ax.set_xticks(df.index)
ax.set_xticklabels(list(df[0]))

enter image description here

Upvotes: 6

Related Questions