Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3283,9 +3283,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
if explode is None:
explode = [0] * len(x)
if len(x) != len(labels):
raise ValueError("'label' must be of length 'x'")
raise ValueError(f"'labels' must be of length 'x', not {len(labels)}")
if len(x) != len(explode):
raise ValueError("'explode' must be of length 'x'")
raise ValueError(f"'explode' must be of length 'x', not {len(explode)}")
if colors is None:
get_next_color = self._get_patches_for_fill.get_next_color
else:
Expand All @@ -3298,7 +3298,7 @@ def get_next_color():

_api.check_isinstance(Real, radius=radius, startangle=startangle)
if radius <= 0:
raise ValueError(f'radius must be a positive number, not {radius}')
raise ValueError(f"'radius' must be a positive number, not {radius}")

# Starting theta1 is the start fraction of the circle
theta1 = startangle / 360
Expand Down
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6149,6 +6149,27 @@ def test_pie_get_negative_values():
ax.pie([5, 5, -3], explode=[0, .1, .2])


def test_pie_invalid_explode():
# Test ValueError raised when feeding short explode list to axes.pie
fig, ax = plt.subplots()
with pytest.raises(ValueError):
ax.pie([1, 2, 3], explode=[0.1, 0.1])


def test_pie_invalid_labels():
# Test ValueError raised when feeding short labels list to axes.pie
fig, ax = plt.subplots()
with pytest.raises(ValueError):
ax.pie([1, 2, 3], labels=["One", "Two"])


def test_pie_invalid_radius():
# Test ValueError raised when feeding negative radius to axes.pie
fig, ax = plt.subplots()
with pytest.raises(ValueError):
ax.pie([1, 2, 3], radius=-5)


def test_normalize_kwarg_pie():
fig, ax = plt.subplots()
x = [0.3, 0.3, 0.1]
Expand Down
Loading