1

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'

4

2 回答 2

2

假设您的数据框名为df

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

由于我无法使用您的确切列标签轻松构建示例版本,因此可能需要稍微修改一下以摆脱包含在转置中diff并随转置移动的任何索引列。但这有助于在随机数据示例上为我制作一个简单的热图。

然后,您可以创建一个 matplotlib 图形或轴对象,并为 x 轴和 y 轴标签指定您想要的任何内容。

于 2013-10-16T14:55:27.900 回答
0

您可以为具有偏移量的每一行一次绘制一条线:

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')

重叠线

如果您不需要填充颜色来阻止上一行,则可以一次完成所有操作:

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

未填写

于 2013-10-16T17:08:01.950 回答