问题描述
我目前有一个如下所示的表格,但是我试图用plotnine绘制一个最小和最大间隔,为此我试图以一种更排序的顺序进行绘制,因为这很混乱。目前,我正在按数据的“真实”列进行排序,但这似乎没有任何效果。
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','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)
解决方法
您需要确保normalized_sorted_table
实际上沿true
列排序,即
normalized_sorted_table = normalized_sorted_table.sort_values('true',ignore_index=True)