0

I have a data in this format.

enter image description here

Using the data above, I created a graph using code below.

from matplotlib import pyplot

pyplot.figure(figsize=(12,8))
pyplot.plot(df_movie['date'], df_movie['rate'], label = 'rating')
pyplot.xticks(rotation=90)
pyplot.legend(loc='best')
pyplot.grid()
pyplot.show()

Below is the result of this code.

Result of the code

There is xticks label for every single date. But I want xticks labels to be shown by every week or every other 10 days or so on. How can I do this?

Thank you

Dohun
  • 477
  • 2
  • 7
  • 13

2 Answers2

0

Here's a very simple way of doing it. You can set the parameter interval to 7 or 10 or any other value you fancy:

import matplotlib.pyplot as plt
import matplotlib.ticker as tkr

x = list('ABCDEFGHIJ')
y = [1,2,4,8,16,32,64,128,256,512]

fig, ax = plt.subplots(1)

interval = 2 # This parameter regulates the interval between xticks

plt.plot(x,y)
ax.xaxis.set_major_locator(tkr.MultipleLocator(interval))
plt.show()

enter image description here

TitoOrt
  • 1,265
  • 1
  • 11
  • 13
0

You should first set your date column to the right type.

df_amovie['date'] = pd.to_datetime(df_amovie['date'])

Then if you plot you will probably get the desired result.

Lukas Belck
  • 30
  • 2
  • 8
  • Thank you for the answer but I want to specify the interval of xtick label rather than default. – Dohun Apr 23 '20 at 16:39