Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Jupyter:如何以固定高度绘制多个直方图?_Python_Pandas_Matplotlib_Jupyter - Fatal编程技术网

Python Jupyter:如何以固定高度绘制多个直方图?

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

我有一个包含多列的数据框,我想同时绘制它们的直方图。DataFrame对象有一个非常好的子地块参数,用于在其各自的轴上绘制每个变量:

%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:]?