0

I currently have a table as seen below, however I am trying to plot a min and max interval with plotnine, for which I am trying to plot in a more sorted order as it is a mess. Currently I am sorting by the "true"column of my data but this does not seem to have any effect.

DataFrame

enter image description here

CODE

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

Current Output:

enter image description here

Desired Output:

enter image description here

USING:

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

enter image description here

1 Answer 1

0

You need to make sure that normalized_sorted_table actually sorted along the true column i.e

normalized_sorted_table = normalized_sorted_table.sort_values('true', ignore_index=True)
Sign up to request clarification or add additional context in comments.

2 Comments

when I do that it turns it, into just a straight line, as seen above
Find out why the order is wrong in the first place. Maybe you need to do a reset_index.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.