8000 Reuse the alias map. · matplotlib/matplotlib@1fa2892 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1fa2892

Browse files
committed
Reuse the alias map.
1 parent 08a92e5 commit 1fa2892

File tree

4 files changed

+20
-39
lines changed

4 files changed

+20
-39
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@
4747

4848
rcParams = matplotlib.rcParams
4949

50-
_alias_map = {'color': ['c'],
51-
'linewidth': ['lw'],
52-
'linestyle': ['ls'],
53-
'facecolor': ['fc'],
54-
'edgecolor': ['ec'],
55-
'markerfacecolor': ['mfc'],
56 10000 -
'markeredgecolor': ['mec'],
57-
'markeredgewidth': ['mew'],
58-
'markersize': ['ms'],
59-
}
60-
6150

6251
def _plot_args_replacer(args, data):
6352
if len(args) == 1:
@@ -1377,7 +1366,7 @@ def plot(self, *args, **kwargs):
13771366
self.cla()
13781367
lines = []
13791368

1380-
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
1369+
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
13811370

13821371
for line in self._get_lines(*args, **kwargs):
13831372
self.add_line(line)
@@ -1952,7 +1941,7 @@ def bar(self, *args, **kwargs):
19521941
%(Rectangle)s
19531942
19541943
"""
1955-
kwargs = cbook.normalize_kwargs(kwargs, mpatches._patch_alias_map)
1944+
kwargs = cbook.normalize_kwargs(kwargs, mpatches.Patch._alias_map)
19561945
# this is using the lambdas to do the arg/kwarg unpacking rather
19571946
# than trying to re-implement all of that logic our selves.
19581947
matchers = [
@@ -2796,7 +2785,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
27962785
27972786
%(Line2D)s
27982787
"""
2799-
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
2788+
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
28002789
# anything that comes in as 'None', drop so the default thing
28012790
# happens down stream
28022791
kwargs = {k: v for k, v in kwargs.items() if v is not None}
@@ -4692,7 +4681,8 @@ def fill(self, *args, **kwargs):
46924681
if not self._hold:
46934682
self.cla()
46944683

4695-
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
4684+
# For compatibility(!), get aliases from Line2D rather than Patch.
4685+
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
46964686

46974687
patches = []
46984688
for poly in self._get_patches_for_fill(*args, **kwargs):
@@ -4764,12 +4754,11 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
47644754
"""
47654755

47664756
if not rcParams['_internal.classic_mode']:
4767-
color_aliases = mcoll._color_aliases
4768-
kwargs = cbook.normalize_kwargs(kwargs, color_aliases)
4769-
4770-
if not any(c in kwargs for c in ('color', 'facecolors')):
4771-
fc = self._get_patches_for_fill.get_next_color()
4772-
kwargs['facecolors'] = fc
4757+
kwargs = cbook.normalize_kwargs(
4758+
kwargs, mcoll.Collection._alias_map)
4759+
if not any(c in kwargs for c in ('color', 'facecolor')):
4760+
kwargs['facecolor'] = \
4761+
self._get_patches_for_fill.get_next_color()
47734762

47744763
# Handle united data, such as dates
47754764
self._process_unit_info(xdata=x, ydata=y1, kwargs=kwargs)
@@ -4924,12 +4913,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
49244913
"""
49254914

49264915
if not rcParams['_internal.classic_mode']:
4927-
color_aliases = mcoll._color_aliases
4928-
kwargs = cbook.normalize_kwargs(kwargs, color_aliases)
4916+
kwargs = cbook.normalize_kwargs(
4917+
kwargs, mcoll.Collection._alias_map)
4918+
if not any(c in kwargs for c in ('color', 'facecolor')):
4919+
kwargs['facecolor'] = \
4920+
self._get_patches_for_fill.get_next_color()
49294921

4930-
if not any(c in kwargs for c in ('color', 'facecolors')):
4931-
fc = self._get_patches_for_fill.get_next_color()
4932-
kwargs['facecolors'] = fc
49334922
# Handle united data, such as dates
49344923
self._process_unit_info(ydata=y, xdata=x1, kwargs=kwargs)
49354924
self._process_unit_info(xdata=x2)

lib/matplotlib/cbook/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,9 @@ def _define_aliases(local_d, alias_d):
27792779
class so far, an alias named ``get_alias`` will be defined; the same will
27802780
be done for setters. If neither the getter nor the setter exists, an
27812781
exception will be raised.
2782+
2783+
The alias map is stored as the ``_alias_map`` attribute on the class and
2784+
can be used by `~.normalize_kwargs`.
27822785
"""
27832786

27842787
def make_alias(name): # Enfore a closure over *name*.
@@ -2798,3 +2801,5 @@ def method(self, *args, **kwargs):
27982801
local_d[prefix + alias] = method
27992802
if not exists:
28002803
raise ValueError("property {} does not exist".format(prop))
2804+
2805+
local_d["_alias_map"] = alias_d

lib/matplotlib/collections.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
CIRCLE_AREA_FACTOR = 1.0 / np.sqrt(np.pi)
3939

4040

41-
_color_aliases = {'facecolors': ['facecolor'],
42-
'edgecolors': ['edgecolor']}
43-
44-
4541
class Collection(artist.Artist, cm.ScalarMappable):
4642
"""
4743
Base class for Collections. Must be subclassed to be usable.

lib/matplotlib/patches.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@
2727
from matplotlib.bezier import make_path_regular, concatenate_paths
2828

2929

30-
_patch_alias_map = {
31-
'antialiased': ['aa'],
32-
'edgecolor': ['ec'],
33-
'facecolor': ['fc'],
34-
'linewidth': ['lw'],
35-
'linestyle': ['ls']
36-
}
37-
38-
3930
class Patch(artist.Artist):
4031
"""
4132
A patch is a 2D artist with a face color and an edge color.

0 commit comments

Comments
 (0)
0