[Python] How to change legend patches after plotting?

Discussão em 'Python' iniciado por Stack, Julho 30, 2025.

  1. Stack

    Stack Membro Participativo

    I have a function that is supposed to enlarge all labels in a figure to make it ready for export. However I fail to enlarge the legend properly:

    import matplotlib.pyplot as plt

    def enlarge_legend(ax, fontSize = 25):
    for text in ax.get_legend().get_texts():
    text.set_fontsize(fontSize)


    fig, ax = plt.subplots()
    ax.scatter(
    [1,2,3],
    [2,3,1],
    label = "auto"
    )
    ax.legend()
    enlarge_legend(ax)


    result:
    [​IMG]

    I would like the circle patch to be bigger as well but both ax.get_legend().get_patches() and ax.get_legend().get_lines() return empty lists. Any idea how to do it?

    Continue reading...

Compartilhe esta Página