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

Skip to content

Commit 413144a

Browse files
committed
Reuse the alias map.
1 parent ef7a035 commit 413144a

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
@@ -48,17 +48,6 @@
4848

4949
rcParams = matplotlib.rcParams
5050

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

6352
def _plot_args_replacer(args, data):
6453
if len(args) == 1:
@@ -1519,7 +1508,7 @@ def plot(self, *args, **kwargs):
15191508
self.cla()
15201509
lines = []
15211510

1522-
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
1511+
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
15231512

15241513
for line in self._get_lines(*args, **kwargs):
15251514
self.add_line(line)
@@ -2090,7 +2079,7 @@ def bar(self, *args, **kwargs):
20902079
%(Rectangle)s
20912080
20922081
"""
2093-
kwargs = cbook.normalize_kwargs(kwargs, mpatches._patch_alias_map)
2082+
kwargs = cbook.normalize_kwargs(kwargs, mpatches.Patch._alias_map)
20942083
# this is using the lambdas to do the arg/kwarg unpacking rather
20952084
# than trying to re-implement all of that logic our selves.
20962085
matchers = [
@@ -3035,7 +3024,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
30353024
.. [Notes section required for data comment. See #10189.]
30363025
30373026
"""
3038-
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
3027+
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
30393028
# anything that comes in as 'None', drop so the default thing
30403029
# happens down stream
30413030
kwargs = {k: v for k, v in kwargs.items() if v is not None}
@@ -4928,7 +4917,8 @@ def fill(self, *args, **kwargs):
49284917
if not self._hold:
49294918
self.cla()
49304919

4931-
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
4920+
# For compatibility(!), get aliases from Line2D rather than Patch.
4921+
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
49324922

49334923
patches = []
49344924
for poly in self._get_patches_for_fill(*args, **kwargs):
@@ -5022,12 +5012,11 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
50225012
50235013
"""
50245014
if not rcParams['_internal.classic_mode']:
5025-
color_aliases = mcoll._color_aliases
5026-
kwargs = cbook.normalize_kwargs(kwargs, color_aliases)
5027-
5028-
if not any(c in kwargs for c in ('color', 'facecolors')):
5029-
fc = self._get_patches_for_fill.get_next_color()
5030-
kwargs['facecolors'] = fc
5015+
kwargs = cbook.normalize_kwargs(
5016+
kwargs, mcoll.Collection._alias_map)
5017+
if not any(c in kwargs for c in ('color', 'facecolor')):
5018+
kwargs['facecolor'] = \
5019+
self._get_patches_for_fill.get_next_color()
50315020

50325021
# Handle united data, such as dates
50335022
self._process_unit_info(xdata=x, ydata=y1, kwargs=kwargs)
@@ -5204,12 +5193,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
52045193
52055194
"""
52065195
if not rcParams['_internal.classic_mode']:
5207-
color_aliases = mcoll._color_aliases
5208-
kwargs = cbook.normalize_kwargs(kwargs, color_aliases)
5196+
kwargs = cbook.normalize_kwargs(
5197+
kwargs, mcoll.Collection._alias_map)
5198+
if not any(c in kwargs for c in ('color', 'facecolor')):
5199+
kwargs['facecolor'] = \
5200+
self._get_patches_for_fill.get_next_color()
52095201

5210-
if not any(c in kwargs for c in ('color', 'facecolors')):
5211-
fc = self._get_patches_for_fill.get_next_color()
5212-
kwargs['facecolors'] = fc
52135202
# Handle united data, such as dates
52145203
self._process_unit_info(ydata=y, xdata=x1, kwargs=kwargs)
52155204
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
@@ -2818,6 +2818,9 @@ def _define_aliases(local_d, alias_d):
28182818
class so far, an alias named ``get_alias`` will be defined; the same will
28192819
be done for setters. If neither the getter nor the setter exists, an
28202820
exception will be raised.
2821+
2822+
The alias map is stored as the ``_alias_map`` attribute on the class and
2823+
can be used by `~.normalize_kwargs`.
28212824
"""
28222825

28232826
def make_alias(name): # Enfore a closure over *name*.
@@ -2837,3 +2840,5 @@ def method(self, *args, **kwargs):
28372840
local_d[prefix + alias] = method
28382841
if not exists:
28392842
raise ValueError("property {} does not exist".format(prop))
2843+
2844+
local_d["_alias_map"] = alias_d

lib/matplotlib/collections.py

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

3131

32-
_color_aliases = {'facecolors': ['facecolor'],
33-
'edgecolors': ['edgecolor']}
34-
35-
3632
class Collection(artist.Artist, cm.ScalarMappable):
3733
"""
3834
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
@@ -19,15 +19,6 @@
1919
split_bezier_intersecting_with_closedpath, split_path_inout)
2020
from .path import Path
2121

22-
_patch_alias_map = {
23-
'antialiased': ['aa'],
24-
'edgecolor': ['ec'],
25-
'facecolor': ['fc'],
26-
'linewidth': ['lw'],
27-
'linestyle': ['ls']
28-
}
29-
30-
3122
class Patch(artist.Artist):
3223
"""
3324
A patch is a 2D artist with a face color and an edge color.

0 commit comments

Comments
 (0)