【问题标题】:How to show all the labels in matplotlib?如何显示 matplotlib 中的所有标签?
【发布时间】:2021-02-04 08:44:57
【问题描述】:

我正在尝试使用 matplotlib 显示图表。但是我的标签太大了,以至于它们相互重叠。我想清楚地显示它没有重叠。我怎样才能做到这一点?我现在使用下面的代码:

import matplotlib.pyplot as plt

x = ['jdwdw723@gmail.com' ,'emcast.test10@gmail.com', 'pbChinaTester@clp.com']
y = [10,25,6]

plt.plot(x,y)

plt.xlabel("loginId")
plt.ylabel("times appeared in the data")

plt.title("loginId Graph")
plt.tight_layout()
plt.show()

【问题讨论】:

  • 您可以将标签旋转 90 度吗? plt.tick_params(axis='x', labelrotation=90)?

标签: python python-3.x pandas matplotlib data-visualization


【解决方案1】:

我尝试了您的示例代码,但似乎没有重叠。有很多可能性。一种常用的方法是旋转标签。

你可以这样做:

plt.xticks(rotation=45)

Changing the “tick frequency” on x or y axis in matplotlib?reducing number of plot ticks 中有更多想法。

我创建了an example notebook here,请随意复制和使用它。

【讨论】:

    猜你喜欢
    • 2014-11-25
    • 2021-11-17
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多