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

Skip to content

Commit ab53432

Browse files
committed
WIP
1 parent 677d990 commit ab53432

File tree

8 files changed

+305
-119
lines changed

8 files changed

+305
-119
lines changed

galleries/examples/misc/svg_filter_pie.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828

2929
# We want to draw the shadow for each pie, but we will not use "shadow"
3030
# option as it doesn't save the references to the shadow patches.
31-
pies = ax.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%')
31+
pies = ax.pie(fracs, explode=explode,
32+
wedge_labels=[labels, '{frac:.1%}'], wedge_label_distance=[1.1, 0.6])
3233

33-
for w in pies[0]:
34+
for w, label in zip(pies[0], labels):
3435
# set the id with the label.
35-
w.set_gid(w.get_label())
36+
w.set_gid(label)
3637

3738
# we don't want to draw the edge of the pie
3839
w.set_edgecolor("none")

galleries/examples/pie_and_polar_charts/bar_of_pie.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
explode = [0.1, 0, 0]
2626
# rotate so that first wedge is split by the x-axis
2727
angle = -180 * overall_ratios[0]
28-
wedges, *_ = ax1.pie(overall_ratios, autopct='%1.1f%%', startangle=angle,
29-
labels=labels, explode=explode)
28+
wedges, *_ = ax1.pie(
29+
overall_ratios, startangle=angle, explode=explode,
30+
wedge_labels=[labels, '{frac:.1%}'], wedge_label_distance=[1.1, 0.6])
3031

3132
# bar chart parameters
3233
age_ratios = [.33, .54, .07, .06]

galleries/examples/pie_and_polar_charts/pie_and_donut_labels.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,16 @@
3838
"250 g butter",
3939
"300 g berries"]
4040

41-
data = [float(x.split()[0]) for x in recipe]
41+
data = [int(x.split()[0]) for x in recipe]
4242
ingredients = [x.split()[-1] for x in recipe]
4343

44+
ax.pie(data, wedge_labels='{frac:.1%}\n({abs:d}g)', labels=ingredients,
45+
labeldistance=None, textprops=dict(color="w", size=8, weight="bold"))
4446

45-
def func(pct, allvals):
46-
absolute = int(np.round(pct/100.*np.sum(allvals)))
47-
return f"{pct:.1f}%\n({absolute:d} g)"
48-
49-
50-
wedges, texts, autotexts = ax.pie(data, autopct=lambda pct: func(pct, data),
51-
textprops=dict(color="w"))
52-
53-
ax.legend(wedges, ingredients,
54-
title="Ingredients",
47+
ax.legend(title="Ingredients",
5548
loc="center left",
5649
bbox_to_anchor=(1, 0, 0.5, 1))
5750

58-
plt.setp(autotexts, size=8, weight="bold")
59-
6051
ax.set_title("Matplotlib bakery: A pie")
6152

6253
plt.show()
@@ -97,7 +88,7 @@ def func(pct, allvals):
9788

9889
data = [225, 90, 50, 60, 100, 5]
9990

100-
wedges, texts = ax.pie(data, wedgeprops=dict(width=0.5), startangle=-40)
91+
wedges, _ = ax.pie(data, wedgeprops=dict(width=0.5), startangle=-40)
10192

10293
bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
10394
kw = dict(arrowprops=dict(arrowstyle="-"),

lib/matplotlib/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137

138138
import atexit
139139
from collections import namedtuple
140-
from collections.abc import MutableMapping
140+
from collections.abc import MutableMapping, Sequence
141141
import contextlib
142142
import functools
143143
import importlib
@@ -1377,14 +1377,17 @@ def _init_tests():
13771377

13781378
def _replacer(data, value):
13791379
"""
1380-
Either returns ``data[value]`` or passes ``data`` back, converts either to
1381-
a sequence.
1380+
Either returns ``data[value]`` or passes ``value`` back, converts either to
1381+
a sequence. If ``value`` is a non-string sequence, processes each element
1382+
and returns a list.
13821383
"""
13831384
try:
13841385
# if key isn't a string don't bother
13851386
if isinstance(value, str):
13861387
# try to use __getitem__
13871388
value = data[value]
1389+
elif isinstance(value, Sequence):
1390+
return [_replacer(data, x) for x in value]
13881391
except Exception:
13891392
# key does not exist, silently fall back to key
13901393
pass
@@ -1459,7 +1462,9 @@ def func(ax, *args, **kwargs): ...
14591462
- if called with ``data=None``, forward the other arguments to ``func``;
14601463
- otherwise, *data* must be a mapping; for any argument passed in as a
14611464
string ``name``, replace the argument by ``data[name]`` (if this does not
1462-
throw an exception), then forward the arguments to ``func``.
1465+
throw an exception), then forward the arguments to ``func``. For any
1466+
argument passed as a non-string sequence, replace any string elements
1467+
by ``data[name]`` (if that does not throw an exception).
14631468
14641469
In either case, any argument that is a `MappingView` is also converted to a
14651470
list.

0 commit comments

Comments
 (0)