【问题标题】:How to increment X-Axis tick marks correctly so it is readable and evenly spaced?如何正确增加 X 轴刻度线,使其可读且均匀分布?
【发布时间】:2022-01-25 07:24:21
【问题描述】:

我正在使用 pandas 和 matplot 来绘制这个数据集,我使用的是以下内容:

data.plot(kind = 'scatter', x="Avg" , y="# Ratings")
plt.show()

Y 轴显示正确,但 X 轴为每个数据点绘制一个刻度,如下所示:

我希望像带有刻度线的 Y 轴那样分布得更均匀、更易读。 我试过 data.xticks 效果不太好

【问题讨论】:

  • 您可能需要将 x 值转换为数字(或 matplotlib 日期)。

标签: python pandas matplotlib plot


【解决方案1】:

你可以使用MaxNLocator:

from matplotlib.ticker import MaxNLocator

ax = data.plot(kind = 'scatter', x="Avg" , y="# Ratings")
ax.xaxis.set_major_locator(MaxNLocator(20))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2021-08-11
    • 2017-05-13
    • 2015-11-05
    • 1970-01-01
    相关资源
    最近更新 更多