在 Matplotlib 中创建 pdp 图的子图

Aar*_*and 6 python plot matplotlib

我正在pdpbox为模型中的 50 个特征中的每一个创建 pdp 图。我已经使用以下方法成功创建并保存了这些图:

# pdp_plot (https://pdpbox.readthedocs.io/en/latest/pdp_plot.html)
for i, feat in enumerate(list_features):
    # increase i by 1 to help with name formatting
    n_feat = i + 1

    # pdp_isolate (https://pdpbox.readthedocs.io/en/latest/pdp_isolate.html)
    pdp_dove = pdp.pdp_isolate(model=model,
                               dataset=df_train,
                               model_features=list_features,
                               feature=feat)

    # generate plot
    fig, axes = pdp.pdp_plot(pdp_isolate_out=pdp_dove,
                             feature_name=feat,
                             plot_pts_dist=True)

    # save figure
    if n_feat < 10:
        n_feat = '0{0}'.format(n_feat)
    # save figure
    plt.savefig('{0}_pdp_{1}.png'.format(n_feat, feat))
Run Code Online (Sandbox Code Playgroud)

如果我愿意,我可以停在这里,因为我的工作目录中的所有绘图都以格式化和有组织的方式保存。但是,我想知道是否可以使用nrows=5和将每个图添加到子图网格中ncols=10。先感谢您!