0

I need to create a graph where the x axis is dates and the y axis is the frequency of a certain event on that day. My issues are plotting with plt.bar() is that as I have values for every day over 8 years, the x axis has far too many labels to be legible. How do I change it so it only shows the years rather than having labels for every day?

I've tried this

# data == dict, keys == 'yyyy-mm-dd'
plt.bar(data.keys(), data.values())
ticks = []
for key in data.keys():
    ticks.append(key[0:4]) # Gets only years. 
ticks = list(set(ticks)) # Get rid of duplicates. 
plt.xticks(ticks)
plt.show()

But the new xticks bunch together at the end on top of one another.

Alesi Rowland
  • 379
  • 2
  • 16

1 Answers1

0

You can specify both the ticks labels and locations. pyplot.xticks([0, 0.5, 1, 1, 1], ('A', 'B', 'C', 'D', 'E')) results in: enter image description here

And pyplot.xticks(numpy.arange(5), ('A', 'B', 'C', 'D', 'E')): enter image description here