首页 > 解决方案 > 增加每个子图的大小并调整它们的宽度,matplotlib

问题描述

我有一个来自 sci-kit learn 的数据集,fetch_lfw_people。

import matplotlib.pyplot as plt
# plotting faces
fig, ax = plt.subplots(3,5)
# fig.subplots_adjust(wspace=2)

for enumerate_counter, axi in enumerate(ax.flat):
    axi.imshow(faces.images[enumerate_counter], cmap='bone')
    axi.set(xticks=[], yticks=[],xlabel=faces.target_names[faces.target[enumerate_counter]])

在尝试使用子图显示图像并使用正确名称标记每个图像时,我想增加每个图像的大小并将它们分开足够宽以使名称不会重叠。

我试过了

fig.subplots_adjust(wspace=2)

但是,这会将图像分开,因此名称不会重叠,但是图像的尺寸会变小。

无论如何我可以解决这个问题吗?

标签: pythonmatplotlibscikit-learn

解决方案


我将给出一些示例,其中包含一些示例编号,这些示例可能会引导您朝着正确的方向前进:

plt.figure(figsize=(20,10)) 

或者

fig, ax = plt.subplots(figsize=(20, 10))

推荐阅读