Python Jupyter:如何以固定高度绘制多个直方图?
我有一个包含多列的数据框,我想同时绘制它们的直方图。DataFrame对象有一个非常好的子地块参数,用于在其各自的轴上绘制每个变量:Python Jupyter:如何以固定高度绘制多个直方图?,python,pandas,matplotlib,jupyter,Python,Pandas,Matplotlib,Jupyter,我有一个包含多列的数据框,我想同时绘制它们的直方图。DataFrame对象有一个非常好的子地块参数,用于在其各自的轴上绘制每个变量: %matplotlib inline # same problem with %matplotlib notebook df.iloc[:,-3:].plot.hist(subplots=True); 给我: 问题是当我尝试绘制更多的列时: %matplotlib inline # 15 variables df.iloc[:,-15:].plot.hist(s
%matplotlib inline # same problem with %matplotlib notebook
df.iloc[:,-3:].plot.hist(subplots=True);
给我:
问题是当我尝试绘制更多的列时:
%matplotlib inline
# 15 variables
df.iloc[:,-15:].plot.hist(subplots=True);
我希望能够设置每个轴的固定高度,并有一个非常大的图像,或者能够滚动查看所有轴
如何操作?一种方法是在绘图前调用plt.subplot来扩展图形的垂直尺寸,如下所示:
nvars = 12 # Example number of variables
# subplots(number of vertically stacked axis positions,
# number of horizontally stacked axis positions,
# figsize=(width, height))
fig, ax = plt.subplots(nvars, 1, figsize=(6, 4*nvars))
# Need to pass axis handle to df.plot()
df.iloc[:,-nvars:].plot.hist(subplots=True, ax=ax);
它不应该是df.iloc[:,-nvars:]?