[Python] How to remove legend in lmplot function of seaborn?

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    In seaborn lmplot function we have hue argument that will automatically draw a colorbar on the right side. How can I disable/remove the colorbar?

    Here are a sample code that will generate a colorbar

    df = pd.DataFrame({'x':[1,2,3,1,2,3,1,2,3],'y':[1,2,3,2,3,4,3,4,5],'color':['a','a','a','b','b','b','c','c','c']})
    facets = sns.lmplot(data=df, x='x', y='y', hue='color', fit_reg=False)
    facets.fig.show()


    [​IMG]

    I tried to call the colorbar object and remove it. In the traditional matplotlib way we can use

    collection = ax.scatter(x='a', y='b', data=df)
    colorbar = fig.colorbar(collection)


    to call it, but I can't see how it works for lmplot. Another alternative way is in sns.heatmap function, where it provides a cbar argument

    sns.heatmap(crosstab, cbar=False)


    But in lmplot there is not cbar option. What is the best way to do it in lmplot?

    Continue reading...

Compartilhe esta Página