lineplot not giving the desired results

Viewed 24
Scenarios Node-0 Node-1 Node-2 Node-3 Node-4 Node-5
Original System 1 1 1 1 1 1
Leak_Node_1 1 0.043 1 1 1 0.0043
Leak_Node_2 1 1 1 1 1 0.012
Leak_Node_3 1 1 1 1 1 0.0086
Leak_Node_4 1 1 1 1 1 0.0085
Leak_Node_5 1 1 1 1 1 0.0076

How do I get the exact kind of line plot in the link below: https://drive.google.com/file/d/19_RVA9t7YvarTmc4W1Im2DtqevHvvZG0/view?usp=sharing

I tried using the code below:
pi1.plot.line()

2 Answers

You have to transpose you DataFrame, because pandas evaluates columns and in your example the figure plots the rows.

from io import StringIO
import pandas as pd
t="""Scenarios  Node-0  Node-1  Node-2  Node-3  Node-4  Node-5
Original System     1   1   1   1   1   1
Leak_Node_1     1   0.043   1   1   1   0.0043
Leak_Node_2     1   1   1   1   1   0.012
Leak_Node_3     1   1   1   1   1   0.0086
Leak_Node_4     1   1   1   1   1   0.0085
Leak_Node_5     1   1   1   1   1   0.0076"""
df = pd.read_csv(StringIO(t), sep='\s\s+', index_col=0, engine='python')
df.T.plot.line()

Result

Make sure to set 'Scenarios' as index in the dataframe and transpose it before plotting.

pi1.set_index('Scenarios').transpose().plot.line()

It should give you this results:
resulting plot with transposed dataframe

Note: If you need to match the colors too (since you stated exactly), use the color argument of df.plot.line() (see the documentation here)

Related