Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib x-axis overlap

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. enter image description here

enter image description here

like image 838
Aren Mark Boghozian Avatar asked Dec 01 '22 10:12

Aren Mark Boghozian


1 Answers

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:

enter image description here

like image 73
Scott Boston Avatar answered Dec 30 '22 16:12

Scott Boston