Pandas中不同大小的多个数据帧的直方图?

2024-04-26 20:58:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试生成一个多图例柱状图(example)。问题是数据帧的长度(大小)不同。如果大小(本例中为30和10)相同,下面的代码就可以工作了。有没有办法仍然生成直方图,我可以比较多个数据系列?在

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

orig = pd.DataFrame(np.random.random(30))
short = pd.DataFrame(np.random.random(10))
combine = pd.DataFrame({'orig' : orig, 'short' : short})

plt.figure()
h = combine.plot(kind='hist', logy=True)
f = h.get_figure()
f.savefig('figures/combined.png')

Tags: 数据importdataframeexampleasnppltrandom