【问题标题】:Fixing the order of x labels in pandas plot修复熊猫图中 x 标签的顺序
【发布时间】:2016-06-03 06:20:41
【问题描述】:

我有下面的图表,现在我想要标签的固定顺序从小到大,但是 pandas 重新排列它们以获得漂亮的图表。我希望它修复,以便更容易并排比较许多图表。

这是我正在使用的代码:

def faultDistributionPlotSaveToDisk(key):
    sample_cut = pd.cut(freq_sample[key], bins=[1,10,100, 1000 ,100000], labels=["(1-10]", "(10-100]", "(100-1000]", "(1000-max]"])
    plot = sample_cut.value_counts(normalize=True).plot()
    fig = plot.get_figure()
    fig.savefig(key + ".png")

【问题讨论】:

  • 您需要显示用于获取该图表的代码。
  • 抱歉,升技压力大,修好了

标签: python pandas plot


【解决方案1】:

您可以将sort=False 传递给value_counts()

plot = sample_cut.value_counts(normalize=True, sort=False).plot()

这将禁用按值降序排序。

【讨论】:

    猜你喜欢
    • 2017-09-20
    • 2016-04-10
    • 2021-09-03
    • 2016-12-16
    • 2021-11-05
    • 2017-01-31
    • 2019-10-01
    • 2014-02-24
    相关资源
    最近更新 更多