bioinformatics_student
bioinformatics_student

Reputation: 488

Plotting Sorted Values Seaborn

I'm trying to plot a lineplot by sorting to a specific column, however this gets out of order when sorting and trying to plot using seaborn. I've been ordering by the true column but come with the following plot.

normalized_evaluation_table = get_evaluation_table(normalized_prediction_intervals, normalized_interval_size, y_test)
#normalized_evaluation_table
normalized_sorted_table = normalized_evaluation_table.sort_values("true", ignore_index = True).reset_index()
normalized_sorted_table
sorted_data_long = normalized_sorted_table.melt(value_vars=['min', 'true', 'max']).reset_index()
sorted_data_long
ax = sns.lineplot(x="index", y="value", data=sorted_data_long, hue = "variable")

Dataset Ordered

enter image description here

Current Plot

enter image description here

Output Obtained with Accepted Answer:

enter image description here

Upvotes: 1

Views: 580

Answers (1)

Utpal Kumar
Utpal Kumar

Reputation: 816

You can use matplotlib to plot the data in columns. In this way, you will have more flexibility. If you like the seaborn style of the plot, you can import its style.

import matplotlib.pyplot as plt
plt.style.use("seaborn")

fig, ax = plt.subplots(figsize=(10,6))
ax.plot(sorted_data_long['index'], sorted_data_long['min'], 'b-')
ax.plot(sorted_data_long['index'], sorted_data_long['max'], 'g-')
ax.plot(sorted_data_long['index'], sorted_data_long['true'], 'r-')
plt.show()

Upvotes: 2

Related Questions