python - Matplotlib x 轴重叠

标签 python matplotlib jupyter-notebook

我有两个列表,x_axis 是格式为“12:30:00”的时间列表。 y 轴是百分比值。我需要在图表上绘制所有值,但是由于 x 轴字符串太长,它们会重叠。无论如何我可以让 matplotlib 不在 x 轴上每次都显示吗?任何帮助,将不胜感激。 enter image description here

enter image description here

最佳答案

您可以旋转并打印每第二个刻度标签:

_ = 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)

输出:

enter image description here

关于python - Matplotlib x 轴重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50033189/

相关文章:

python - Pandas - 对每个子集应用转换(在 n 列中选择)

python - 生成满足特定条件的 7 个字母单词列表 - Python

python - 不显示缺失值​matplotlib

python - matplotlib.补丁 : One patch with mulitple colors

python - Matplotlib 动画不显示

python - 在Windows中安装Jupyter Notebook

python - 默认或以编程方式对 TreeView 中的列进行排序

python - Tensorflow:将灰度图像转换为RGB

python - SmartyStreets API 在数据框架中循环

python - Jupyter笔记本找不到模块