首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用plotnine绘制数据帧

使用plotnine绘制数据帧
EN

Stack Overflow用户
提问于 2020-08-25 21:15:25
回答 1查看 161关注 0票数 0

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

DataFrame

代码

代码语言:javascript
复制
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)))

当前输出:

所需输出:

使用:

代码语言:javascript
复制
normalized_sorted_table = normalized_sorted_table.sort_values('true', ignore_index=True)

EN

回答 1

Stack Overflow用户

发布于 2020-08-26 04:35:56

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

代码语言:javascript
复制
normalized_sorted_table = normalized_sorted_table.sort_values('true', ignore_index=True)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63579692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档