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

代码
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)

发布于 2020-08-26 04:35:56
您需要确保normalized_sorted_table实际上是沿着true列排序的,即
normalized_sorted_table = normalized_sorted_table.sort_values('true', ignore_index=True)https://stackoverflow.com/questions/63579692
复制相似问题