Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class _AxesBase(martist.Artist):
ymin: float | None = ...,
ymax: float | None = ...
) -> tuple[float, float, float, float]: ...
def get_legend(self) -> Legend: ...
def get_legend(self) -> Legend | None: ...
def get_images(self) -> list[AxesImage]: ...
def get_lines(self) -> list[Line2D]: ...
def get_xaxis(self) -> XAxis: ...
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9900,3 +9900,16 @@ def test_pie_all_zeros():
fig, ax = plt.subplots()
with pytest.raises(ValueError, match="All wedge sizes are zero"):
ax.pie([0, 0], labels=["A", "B"])


def test_get_legend_return_type():
fig, ax = plt.subplots()

assert ax.get_legend() is None

ax.plot([1, 2], label="Line")
ax.legend()

legend = ax.get_legend()
assert legend is not None
assert isinstance(legend, matplotlib.legend.Legend)
Loading