Back to Seaborn

Move Legend

doc/_docstrings/move_legend.ipynb

0.13.2951 B
Original Source
python
import seaborn as sns
sns.set_theme()
penguins = sns.load_dataset("penguins")
python
ax = sns.histplot(penguins, x="bill_length_mm", hue="species")
sns.move_legend(ax, "center right")
python
ax = sns.histplot(penguins, x="bill_length_mm", hue="species")
sns.move_legend(ax, "upper left", bbox_to_anchor=(1, 1))
python
ax = sns.histplot(penguins, x="bill_length_mm", hue="species")
sns.move_legend(
    ax, "lower center",
    bbox_to_anchor=(.5, 1), ncol=3, title=None, frameon=False,
)
python
g = sns.displot(
    penguins,
    x="bill_length_mm", hue="species",
    col="island", col_wrap=2, height=3,
)
sns.move_legend(g, "upper left", bbox_to_anchor=(.55, .45))
python
g = sns.displot(
    penguins,
    x="bill_length_mm", hue="species",
    col="island", col_wrap=2, height=3,
    facet_kws=dict(legend_out=False),
)
sns.move_legend(g, "upper left", bbox_to_anchor=(.55, .45), frameon=False)