Reputation: 159
I have two lists, x_axis which is list of time in the format of '12:30:00'. The y-axis is percent values. I need to plot all the values on a graph, however since x-axis string is too long they overlap. Is there anyway I can have matplotlib not show every single time on x-axis? Any help would be appreciated.
Upvotes: 12
Views: 36608
Reputation: 617
I needed to step x axis digits instead of rotating.
ax.set_xticks(np.arange(0, max_number, 5)) #step 5 digits
Upvotes: 5
Reputation: 2438
One way to do this automatically is by using autofmt_xdate
fig.autofmt_xdate():
for getting fig object you will have to call the subplot functions
fig, ax = plt.subplots()
Works really well
Upvotes: 3
Reputation: 322
You can rotate your label to show the list time using the below code.
plt.xticks(rotation=90)
Upvotes: 8
Reputation: 153460
You could rotate and print every 2nd ticklabel:
_ = plt.plot(df['str_time'], df.Pct, 'ro')
ax = plt.gca()
plt.axis([0,24,0,50])
plt.xticks(rotation=90)
for label in ax.get_xaxis().get_ticklabels()[::2]:
label.set_visible(False)
Output:
Upvotes: 19