[Python] Improve subplot size/spacing with many subplots

Discussão em 'Python' iniciado por Stack, Março 19, 2025.

  1. Stack

    Stack Membro Participativo

    I need to generate a whole bunch of vertically-stacked plots in matplotlib. The result will be saved using savefig and viewed on a webpage, so I don't care how tall the final image is, as long as the subplots are spaced so they don't overlap.

    No matter how big I allow the figure to be, the subplots always seem to overlap.

    My code currently looks like

    import matplotlib.pyplot as plt
    import my_other_module

    titles, x_lists, y_lists = my_other_module.get_data()

    fig = plt.figure(figsize=(10,60))
    for i, y_list in enumerate(y_lists):
    plt.subplot(len(titles), 1, i)
    plt.xlabel("Some X label")
    plt.ylabel("Some Y label")
    plt.title(titles)
    plt.plot(x_lists,y_list)
    fig.savefig('out.png', dpi=100)

    Continue reading...

Compartilhe esta Página