【发布时间】:2019-08-19 03:42:09
【问题描述】:
我有两个不同的数据框,每个数据框有 19 个变量,我正在用每个变量的直方图绘制一个多重图,如下所示:
fig, ax = plt.subplots(figsize=(19,10), dpi=50)
dataframe1.hist(ax=ax, layout=(3,7), alpha=0.5)
fig, ax = plt.subplots(figsize=(19,10), dpi=50)
dataframe2.hist(ax=ax, layout=(3,7), alpha=0.5)
这会生成两张图像,里面有 19 个直方图。我想尝试的是在同一个子图中只绘制一个具有共享直方图的图像。
我试过这个:
fig, ax = plt.subplots(figsize=(19,10), dpi=50)
dataframe1.hist(ax=ax, layout=(3,7), alpha=0.5, label='x')
dataframe2.hist(ax=ax, layout=(3,7), alpha=0.5, label='y', color='red')
但它只画了最后一张。 这是一个类似的例子:Plot two histograms at the same time with matplotlib 但我如何将它应用到两个我的 19 个子图中?
欢迎任何想法,提前谢谢!
P.S:我目前正在使用带有 %matplotlib notebook 选项的 Jupyter Notebooks
【问题讨论】:
-
我理解正确,您想在同一组轴上显示 19 个 直方图?
-
我刚刚添加了一张图片。我希望每个子图有 2 个直方图而不是 1 个。感谢您的理解!
标签: python pandas matplotlib