【发布时间】:2020-09-17 12:56:59
【问题描述】:
我有 9 个使用 matplotlib.pyplot 制作的直方图。
有没有一种简单的方法可以将它们“粘”在一起,这样每个新的直方图就不会从新行开始?
数据:data
提供代码:
for column in data:
plt.figure(figsize=(5,5))
a1 = data[(data['Outcome'] == 0)][column]
a2 = data[(data['Outcome'] == 1)][column]
ax = np.linspace(0, data[column].max(), 50)
plt.hist(a1, ax, color='blue', alpha=0.6, label='Have Diabetes = NO')
plt.hist(a2, ax, color='yellow', alpha=0.6, label='Have Diabetes = YES')
plt.title(f'Histogram for {column}')
plt.xlabel(f'{column}')
plt.ylabel('number of people')
plt.grid(True)
leg = plt.legend(loc='upper right', frameon=True)
我想要的是这样的:
我实际上不需要它是 3x3,只是不要进入列。可能吗?感谢您提供任何可能的帮助。
【问题讨论】:
-
这是一个非常糟糕的问题,没有任何代码、任何数据、任何关于如何生成这个数字的信息。您当然可以使用
fig, ax = plt.subplots(1, 9)来获取 1 行和 9 列,但是您要如何使用它只取决于您,因为我们没有您的数据和代码 -
添加了代码,但是,我的问题是关于所有地块,而不是这个特定的地块。
标签: python matplotlib