【发布时间】:2014-08-26 23:40:14
【问题描述】:
我正在尝试使用来自 2 个或更多不均匀 pandas 数据帧的数据创建堆叠直方图?到目前为止,我可以让它们相互叠加,但不能堆叠。
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('dert.csv', encoding = "ISO-8859-1", index_col=0)
df1['text'] = df['text'].dropna(subset=['five'])
df2['printed'] = df['text2']
ax = df1['text'].hist( bins=100, range=(1,100), stacked=True, color = 'r')
ax = df2['printed'].hist(bins=100, range=(1,100), stacked=True, color = 'g')
plt.setp(ax.get_xticklabels(), rotation=45)
plt.show()
如何让它们堆叠起来?
我找到了一个解决方案,但它不使用 pandas 数据框Matplotlib, creating stacked histogram from three unequal length arrays
【问题讨论】:
-
您是否尝试过使用与您发布的链接相同的方法?使用常规 matplotlib,只需传递要绘制的 DataFrame 列,应该可以工作。最多可以为每列的值创建一个列表。
标签: python matplotlib pandas graphing