python - Row based chart plot (Seaborn or Matplotlib) -


given data pandas dataframe , looks 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   2013-07-05  2   0.84  1.03  0.96  0.90  1.09  0.59  1.15   2013-08-21  3   0.09  0.25  0.06  0.09 -0.09 -0.16  0.56   2014-10-15  4   0.35  1.16  1.91  3.44  2.75  1.97  2.16   2015-02-09  5   0.09 -0.10 -0.38 -0.69 -0.25 -0.85 -0.47  

how can plot chart of 5 lines (1 each ref), x axis columns (+1, +2...), , starts 0? if in seaborn, better. matplotlib solutions welcome.

plotting dataframe in pandas reshaping table individual lines want in separate columns, , x-values in index. of these reshape operations bit ugly, 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 row have lines start 0: plot_table.loc['+0', :] = 0 plot_table = plot_table.sort_index() plot_table ref          1     2     3     4     5 variable                               +0        0.00  0.00  0.00  0.00  0.00 +1       -0.44  0.84  0.09  0.35  0.09 +2        0.03  1.03  0.25  1.16 -0.10 +3        0.06  0.96  0.06  1.91 -0.38 +4       -0.31  0.90  0.09  3.44 -0.69 +5        0.13  1.09 -0.09  2.75 -0.25 +6        0.56  0.59 -0.16  1.97 -0.85 +7        0.81  1.15  0.56  2.16 -0.47 

now have table right shape, plotting pretty automatic:

plot_table.plot() 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -