Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't document Plot.label as accepting None as a value
  • Loading branch information
mwaskom committed Aug 4, 2022
commit 3cf0437d5130bf09364cad45a31ee1a0fc5eb5be
28 changes: 15 additions & 13 deletions seaborn/_core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from contextlib import contextmanager
from collections import abc
from collections.abc import Callable, Generator, Hashable
from typing import Any, Optional, cast
from typing import Any, cast

from cycler import cycler
import pandas as pd
Expand Down Expand Up @@ -151,7 +151,7 @@ class Plot:

_scales: dict[str, Scale]
_limits: dict[str, tuple[Any, Any]]
_labels: dict[str, str | Callable[[str], str] | None]
_labels: dict[str, str | Callable[[str], str]]
_theme: dict[str, Any]

_facet_spec: FacetSpec
Expand Down Expand Up @@ -599,23 +599,26 @@ def limit(self, **limits: tuple[Any, Any]) -> Plot:
new._limits.update(limits)
return new

def label(self, **labels: str | Callable[[str], str] | None) -> Plot:
def label(self, *, title=None, **variables: str | Callable[[str], str]) -> Plot:
"""
Control the labels used for variables in the plot.
Add or modify labels to axes, legends, and subplots.

For coordinate variables, this sets the axis label.
For semantic variables, it sets the legend title.

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

- string (used literally)
- string (used literally; pass "" to clear the default label)
- function (called on the default label)
- None (disables the label for this variable)

For coordinate variables, this sets the axis label.
For semantic variables, it sets the legend title.

"""
# TODO should col=... add a "label" to the facet titles?
# How does this interact with title=...?
new = self._clone()
new._labels.update(labels)
if title is not None:
new._labels["title"] = title
new._labels.update(variables)
return new

def configure(
Expand Down Expand Up @@ -860,8 +863,7 @@ def _resolve_label(self, p: Plot, var: str, auto_label: str | None) -> str | Non
if callable(manual_label) and auto_label is not None:
label = manual_label(auto_label)
else:
# mypy needs a lot of help here, I'm not sure why
label = cast(Optional[str], manual_label)
label = cast(str, manual_label)
else:
label = auto_label
return label
Expand Down