[Python] Why are the subplots in the subfigures getting smaller?

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

  1. Stack

    Stack Membro Participativo

    I am using gridspec within a subfigure. For some reason matshow plots are getting smaller and smaller.

    import numpy as np
    import matplotlib.pyplot as plt

    mask = np.array([
    [ 1, 0, 1, 0, 1],
    [ 1, 1, 1, 1, 1],
    [ 0, 0, 0, 0, 0],
    [ 1, 1, 1, 1, 1],
    [ 1, 1, 1, 1, 0]
    ])

    fig = plt.figure(figsize = (12,16), layout = "constrained")
    figures = fig.subfigures(4, 2)
    figures = figures.reshape(-1)
    x = np.linspace(0, 1, 100)
    y = x**(0.5)

    for f in figures:
    spec = f.add_gridspec(3, 2)
    for i in range(3):
    image_axis = f.add_subplot(spec[i, 0])
    image_axis.matshow(mask, cmap = 'grey')
    plot_axis = f.add_subplot(spec[:,1])
    plot_axis.plot(x, y)

    plt.savefig('test.png')


    [​IMG]

    Continue reading...

Compartilhe esta Página