【问题标题】:Plotting Dataframes with plotnine用 plotnine 绘制数据框
【发布时间】:2020-08-25 13:15:24
【问题描述】:

我目前有一个如下所示的表格,但是我试图用 plotnine 绘制一个最小和最大间隔,我试图以更有序的顺序绘制它,因为它是一团糟。目前我正在按我的数据的“真实”列进行排序,但这似乎没有任何效果。

数据帧

代码

import pandas.api.types as pdtypes
# Convert to tidy data format, making sure to keep the index
sorted_data_long = normalized_sorted_table.melt(value_vars=['min', 'true', 'max'], ignore_index=False).reset_index()
# Make variable a categorical, with categories ordered so as to make sense in the legend
sorted_data_long['variable'] = sorted_data_long['variable'].astype(pdtypes.CategoricalDtype(['min', 'true', 'max']))
# Plot
p9.options.set_option("figure_size", (16, 8))
(p9.ggplot(sorted_data_long, p9.aes('index', y='value', color='variable'))
 + p9.geom_line()
 + p9.labels.ggtitle("PLS: Intervals")
 + p9.theme_bw()
 + p9.theme(text=p9.element_text(size=22)))

电流输出:

期望的输出:

使用:

normalized_sorted_table = normalized_sorted_table.sort_values('true', ignore_index=True)

【问题讨论】:

    标签: python ggplot2 python-ggplot plotnine


    【解决方案1】:

    您需要确保 normalized_sorted_table 实际上是沿 true 列排序的,即

    normalized_sorted_table = normalized_sorted_table.sort_values('true', ignore_index=True)
    

    【讨论】:

    • 当我这样做时,它会将它变成一条直线,如上所示
    • 首先找出订单错误的原因。也许你需要做一个reset_index
    猜你喜欢
    • 2020-11-05
    • 2020-11-05
    • 1970-01-01
    • 2016-01-31
    • 2018-06-29
    • 2021-02-21
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多