【问题标题】:creating stacked histogram with pandas dataframes data python使用熊猫数据框数据python创建堆叠直方图
【发布时间】: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


【解决方案1】:

该帖子中的方法应该有效:

plt.hist([df1['text'],df2['printed']],
          bins=100, range=(1,100), stacked=True, color = ['r','g'])

【讨论】:

猜你喜欢
  • 2022-06-10
  • 2019-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2015-01-25
  • 1970-01-01
相关资源
最近更新 更多