I'm having a little trouble trying to place evenly spaced ticks in the x_axis using the plot_date of matplotlib
. Let's say I have some data y, (some random data in this case), that are temporally spaced and I would like to add some ticks to the x axis so that the viewer can resolve the corresponding months/weeks and get better insight into the data.
Any idea how this is possible ?
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as ticker
time1 = '2014-08-01'
time2 = '2016-08-31'
start = mdates.strpdate2num('%Y-%m-%d')(time1)
end = mdates.strpdate2num('%Y-%m-%d')(time2)
n = 1000
step = (end-start)/n
x = [x*step +start for x in range(n)]
y = np.random.randint(0,100,n) /100.
plt.rc('text', usetex=True)
plt.rc('font', family='Times',size=20)
fig = plt.figure(figsize=(18, 12))
plt.plot_date(x, y)
plt.savefig('test.png',bbox_inches='tight', format='png')