seaborn.objects.Plot.label#

Plot.label(*, title=None, **variables)#

Control the labels and titles for axes, legends, and subplots.

Additional keywords correspond to variables defined in the plot. Values can be one of the following types:

  • string (used literally; pass “” to clear the default label)

  • function (called on the default label)

For coordinate variables, the value sets the axis label. For semantic variables, the value sets the legend title. For faceting variables, title= modifies the subplot-specific label, while col= and/or row= add a label for the faceting variable. When using a single subplot, title= sets its title.

Examples

Use strings to override default labels:

p = (
    so.Plot(penguins, x="bill_length_mm", y="bill_depth_mm")
    .add(so.Dot(), color="species")
)
p.label(x="Length", y="Depth", color="")
../_images/objects.Plot.label_1_0.png

Pass a function to modify the default label:

p.label(color=str.capitalize)
../_images/objects.Plot.label_3_0.png

Use this method to set the title for a single-axes plot:

p.label(title="Penguin species exhibit distinct bill shapes")
../_images/objects.Plot.label_5_0.png

When faceting, the title parameter will modify default titles:

p.facet("sex").label(title=str.upper)
../_images/objects.Plot.label_7_0.png

And the col/row parameters will add labels to the title for each facet:

p.facet("sex").label(col="Sex:")
../_images/objects.Plot.label_9_0.png

If more customization is needed, a format string can work well:

p.facet("sex").label(title="{} penguins".format)
../_images/objects.Plot.label_11_0.png