简体   繁体   中英

Is there a way for iPython to generate these kinds of charts given a dataframe?

This picture

Please ignore the background image. The foreground chart is what I am interested in showing using pandas or numpy or scipy (or anything in iPython).

I have a dataframe where each row represents temperatures for a single day. This is an example of some rows:

            100   200   300   400   500   600 ...... 2300
10/3/2013  53*C  57*C  48*C  49*C  54*C  54*C        55*C
10/4/2013  45*C  47*C  48*C  49*C  50*C  52*C        57*C

Is there a way to get a chart that represents the changes from hour to hour using the first column as a 'zero'

Something quick and dirty that might get you most of the way there, assuming your data frame is named df :

import matplotlib.pyplot as plt
plt.imshow(df.T.diff().fillna(0.0).T.drop(0, axis=1).values)

Since I can't easily construct a sample version with your exact column labels, there might be slight additional tinkering with getting rid of any index columns that are included in the diff and moved with the transposition. But this worked to make a simple heat-map-ish plot for me on a random data example.

Then you can create a matplotlib figure or axis object and specify whatever you want for the x- and y-axis labels.

You could just plot lines one at a time for each row with an offset:

nrows, ncols = 12, 30

# make up some fake data:
d = np.random.rand(nrows, ncols)
d *= np.sin(2*np.pi*np.arange(ncols)*4/ncols)
d *= np.exp(-0.5*(np.arange(nrows)-nrows/2)**2/(nrows/4)**2)[:,None]

#this is all you need, if you already have the data:
for i, r in enumerate(d):
    plt.fill_between(np.arange(ncols), r+(nrows-i)/2., lw=2, facecolor='white')

重叠线

You could do it all at once if you don't need the fill color to block the previous line:

d += np.arange(nrows)[:, None]
plt.plot(d.T)

未填满

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM