python - Matplotlib tick frequency -
i have list of dates plotting against list of scores.
date = ['5/25/2015', '5/25/2015', '5/3/2015', '2/4/2015', '2/1/2015', '1/25/2015', '12/31/2014', '10/9/2014', '8/26/2014', '7/24/2014', '7/3/2014', .....]` scores = [6.497, 14.915, 9.911, 9.908, 11.99, 10.993, 14.987, .... ]
with equal number of both.
i generating graph follows:
figscore = plt.figure() plt.plot(range(len(scores)), scores) plt.xticks(range(len(scores)), date, size = "small", rotation = 90) plt.tight_layout() name = 'plot.png' figscore.savefig(name)
(no image due <10 rep)
however, can not change tick frequency. x-labels appear every 5 dates on x-axis. have tried multiple methods fix , not work.
not sure if simplest way it, 1 way make list blank except every fifth date. instance:
plotdate = [] idx, val in enumerate(date): if idx%5 == 0: plotdate.append(val) else: plotdate.append('')
and use plotdate list in call plt.xticks rather date variable. seemed work me.
Comments
Post a Comment