Skip to content Skip to sidebar Skip to footer

Row Based Chart Plot (seaborn Or Matplotlib)

Given that my data is a pandas dataframe and looks like this: Ref +1 +2 +3 +4 +5 +6 +7 2013-05-28 1 -0.44 0.03 0.06 -0.31 0.13 0.56 0.81

Solution 1:

Plotting a dataframe in pandas is generally all about reshaping the table so that the individual lines you want are in separate columns, and the x-values are in the index. Some of these reshape operations are a bit ugly, but you can do:

df = pd.read_clipboard()
plot_table = pd.melt(df.reset_index(), id_vars=['index', 'Ref'])
plot_table = plot_table.pivot(index='variable', columns='Ref', values='value')
# Add extra rowto have all lines startfrom0:
plot_table.loc['+0', :] =0
plot_table = plot_table.sort_index()
plot_table
Ref12345
variable                              
+00.000.000.000.000.00+1-0.440.840.090.350.09+20.031.030.251.16-0.10+30.060.960.061.91-0.38+4-0.310.900.093.44-0.69+50.131.09-0.092.75-0.25+60.560.59-0.161.97-0.85+70.811.150.562.16-0.47

Now that you have a table with the right shape, plotting is pretty automatic:

plot_table.plot()

Post a Comment for "Row Based Chart Plot (seaborn Or Matplotlib)"