Pandas: plotting multiple DataFrame timelines in one plot

I have the following pandas DataFrame:

     time      Group      blocks
0     1        A           4
1     2        A           7
2     3        A           12
3     4        A           17
4     5        A           21 
5     6        A           26
6     7        A           33
7     8        A           39
8     9        A           48
9     10       A           59
    ....        ....          ....
36     35      A           231
37     1       B           1
38     2       B           1.5
39     3       B           3
40     4       B           5
41     5       B           6
    ....        ....          ....
911    35      Z           349

This is a data frame with multiple time series data, from min=1to max=35. Everyone Grouphas such a time series.

I would like to build each separate time series from A to Z on the x axis from 1 to 35. The y axis will be blocksat every moment in time.

I was thinking of using something like the Andrews Curves chart , which will display each series against each other. Each “shade” will be set in a different group. (Other ideas are welcome.)

enter image description here

My problem is: how do you format this framework to build multiple episodes? Should columns GroupA, GroupBetc.?

:

time GroupA blocksA GroupsB blocksB GroupsC blocksC....

, ?

:

df.groupby('Group').plot(legend=False)

x . 0 35, .

enter image description here

?

+4
1

. - , - , Month. data Temperature, Day Month:

import pandas as pd
import statsmodels.api as sm
import matplotlib.pylab as plt
from pandas.tools.plotting import andrews_curves

data = sm.datasets.get_rdataset('airquality').data
fig, (ax1, ax2) = plt.subplots(nrows = 2, ncols = 1)
data = data[data.columns.tolist()[3:]] # use only Temp, Month, Day

# Andrews' curves
andrews_curves(data, 'Month', ax=ax1)

# multiline plot with group by
for key, grp in data.groupby(['Month']): 
    ax2.plot(grp['Day'], grp['Temp'], label = "Temp in {0:02d}".format(key))
plt.legend(loc='best')    
plt.show()

, . , , , , .

enter image description here

+4

All Articles