Matplotlib x轴重叠 [英] Matplotlib x-axis overlap
本文介绍了Matplotlib x轴重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个列表,x_axis是时间列表,格式为"12:30:00". y轴是百分比值.我需要在一张图上绘制所有值,但是由于x轴字符串太长,它们会重叠.无论如何,我可以让matplotlib不在x轴上每次都显示吗?任何帮助,将不胜感激.
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.
推荐答案
您可以旋转并打印每个第二个ticklabel:
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)
输出:
这篇关于Matplotlib x轴重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文