Sahil
Sahil

Reputation: 9478

Change the spacing of a pandas plot?

I am plotting a time-series graph using pandas, my data looks like this

1986-87  334
1987-88  331
1988-89  352
1989-90  380
1990-91  386
1991-92  386
1992-93  390
1993-94  403
1994-95  406

My code looks like this

playercount = pd.DataFrame(t.groupby('season').size())
playercount.plot()
plt.show()

enter image description here

I want more zoomed version than this. Currently my one pixel consists of 10 years, I want to modify it to make it more fine-grained i.e. 5 or fewer years. What parameters can I change to achieve this?

Upvotes: 1

Views: 1374

Answers (1)

Alexander
Alexander

Reputation: 109546

To adjust the grid spacing, try adjusting the parameter n below:

n = 5
playercount.plot(xticks=playercount.index[::n], grid=True)

It means that you are using every n'th index value as a tick mark on the x-axis.

If your index is not a timestamp but is a string, then this should work.

playercount.plot(xticks=[i for i in range(len(playercount.index)) if not i % n], grid=True)

Upvotes: 1

Related Questions