[Python] Is it possible to get GridSpec from Figure before adding Axes?

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

  1. Stack

    Stack Membro Participativo

    Consider the following code

    from matplotlib import pyplot as plt

    fig = plt.figure()
    grid = fig.add_gridspec(2,2)


    We have that grid is a GridSpec instance.

    Consider now the following code

    from matplotlib import pyplot as plt

    fig = plt.figure()
    fig.add_gridspec(2,2)


    The only way to retrieve the GridSpec associated to fig that I found is either to use the first code snippet I posted or to add a Subplot first and then get the GridSpec from such a Subplot:

    axes = fig.add_subplot(grid[0])
    grid = axes.get_gridspec()


    But what if I want to get the GridSpec from fig directly and before adding any Subplot?

    Is it possible?

    Continue reading...

Compartilhe esta Página