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

Skip to content

Commit ef7a035

Browse files
committed
Declare all property aliases together.
1 parent da7ffcc commit ef7a035

File tree

5 files changed

+82
-211
lines changed

5 files changed

+82
-211
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,3 +2803,37 @@ def _str_lower_equal(obj, s):
28032803
cannot be used in a boolean context.
28042804
"""
28052805
return isinstance(obj, six.string_types) and obj.lower() == s
2806+
2807+
2808+
def _define_aliases(local_d, alias_d):
2809+
"""Define property aliases.
2810+
2811+
Use in a class definition as ::
2812+
2813+
cbook._define_aliases(locals(), {
2814+
"property": ["alias", ...], ...
2815+
})
2816+
2817+
For each property, if the corresponding ``get_property`` is defined in the
2818+
class so far, an alias named ``get_alias`` will be defined; the same will
2819+
be done for setters. If neither the getter nor the setter exists, an
2820+
exception will be raised.
2821+
"""
2822+
2823+
def make_alias(name): # Enfore a closure over *name*.
2824+
def method(self, *args, **kwargs):
2825+
return getattr(self, name)(*args, **kwargs)
2826+
method.__doc__ = "alias for {}".format(name)
2827+
return method
2828+
2829+
for prop, aliases in alias_d.items():
2830+
exists = False
2831+
for prefix in ["get_", "set_"]:
2832+
if prefix + prop in local_d:
2833+
exists = True
2834+
for alias in aliases:
2835+
method = make_alias(prefix + prop)
2836+
method.__name__ = str(prefix + alias) # Py2 compat.
2837+
local_d[prefix + alias] = method
2838+
if not exists:
2839+
raise ValueError("property {} does not exist".format(prop))

lib/matplotlib/collections.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,6 @@ def set_linewidth(self, lw):
505505
self._us_lw, self._us_linestyles)
506506
self.stale = True
507507

508-
def set_linewidths(self, lw):
509-
"""alias for set_linewidth"""
510-
return self.set_linewidth(lw)
511-
512-
def set_lw(self, lw):
513-
"""alias for set_linewidth"""
514-
return self.set_linewidth(lw)
515-
516508
def set_linestyle(self, ls):
517509
"""
518510
Set the linestyle(s) for the collection.
@@ -640,14 +632,6 @@ def _bcast_lwls(linewidths, dashes):
640632

641633
return linewidths, dashes
642634

643-
def set_linestyles(self, ls):
644-
"""alias for set_linestyle"""
645-
return self.set_linestyle(ls)
646-
647-
def set_dashes(self, ls):
648-
"""alias for set_linestyle"""
649-
return self.set_linestyle(ls)
650-
651635
def set_antialiased(self, aa):
652636
"""
653637
Set the antialiasing state for rendering.
@@ -659,10 +643,6 @@ def set_antialiased(self, aa):
659643
self._antialiaseds = np.atleast_1d(np.asarray(aa, bool))
660644
self.stale = True
661645

662-
def set_antialiaseds(self, aa):
663-
"""alias for set_antialiased"""
664-
return self.set_antialiased(aa)
665-
666646
def set_color(self, c):
667647
"""
668648
Set both the edgecolor and the facecolor.
@@ -704,21 +684,15 @@ def set_facecolor(self, c):
704684
self._original_facecolor = c
705685
self._set_facecolor(c)
706686

707-
def set_facecolors(self, c):
708-
"""alias for set_facecolor"""
709-
return self.set_facecolor(c)
710-
711687
def get_facecolor(self):
712688
return self._facecolors
713-
get_facecolors = get_facecolor
714689

715690
def get_edgecolor(self):
716691
if (isinstance(self._edgecolors, six.string_types)
717692
and self._edgecolors == str('face')):
718693
return self.get_facecolors()
719694
else:
720695
return self._edgecolors
721-
get_edgecolors = get_edgecolor
722696

723697
def _set_edgecolor(self, c):
724698
set_hatch_color = True
@@ -764,10 +738,6 @@ def set_edgecolor(self, c):
764738
self._original_edgecolor = c
765739
self._set_edgecolor(c)
766740

767-
def set_edgecolors(self, c):
768-
"""alias for set_edgecolor"""
769-
return self.set_edgecolor(c)
770-
771741
def set_alpha(self, alpha):
772742
"""
773743
Set the alpha tranparencies of the collection. *alpha* must be
@@ -785,13 +755,11 @@ def set_alpha(self, alpha):
785755
self._set_facecolor(self._original_facecolor)
786756
self._set_edgecolor(self._original_edgecolor)
787757

788-
def get_linewidths(self):
758+
def get_linewidth(self):
789759
return self._linewidths
790-
get_linewidth = get_linewidths
791760

792-
def get_linestyles(self):
761+
def get_linestyle(self):
793762
return self._linestyles
794-
get_dashes = get_linestyle = get_linestyles
795763

796764
def update_scalarmappable(self):
797765
"""
@@ -836,6 +804,14 @@ def update_from(self, other):
836804
# self.update_dict = other.update_dict # do we need to copy this? -JJL
837805
self.stale = True
838806

807+
cbook._define_aliases(locals(), {
808+
"antialiased": ["antialiaseds"],
809+
"edgecolor": ["edgecolors"],
810+
"facecolor": ["facecolors"],
811+
"linestyle": ["linestyles", "dashes"],
812+
"linewidth": ["linewidths", "lw"],
813+
})
814+
839815
# these are not available for the object inspector until after the
840816
# class is built so we define an initial set here for the init
841817
# function and they will be overridden after object defn

lib/matplotlib/lines.py

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,79 +1265,6 @@ def _get_rgba_face(self, alt=False):
12651265
def _get_rgba_ln_color(self, alt=False):
12661266
return mcolors.to_rgba(self._color, self._alpha)
12671267

1268-
# some aliases....
1269-
def set_aa(self, val):
1270-
'alias for set_antialiased'
1271-
self.set_antialiased(val)
1272-
1273-
def set_c(self, val):
1274-
'alias for set_color'
1275-
self.set_color(val)
1276-
1277-
def set_ls(self, val):
1278-
"""alias for set_linestyle"""
1279-
self.set_linestyle(val)
1280-
1281-
def set_lw(self, val):
1282-
"""alias for set_linewidth"""
1283-
self.set_linewidth(val)
1284-
1285-
def set_mec(self, val):
1286-
"""alias for set_markeredgecolor"""
1287-
self.set_markeredgecolor(val)
1288-
1289-
def set_mew(self, val):
1290-
"""alias for set_markeredgewidth"""
1291-
self.set_markeredgewidth(val)
1292-
1293-
def set_mfc(self, val):
1294-
"""alias for set_markerfacecolor"""
1295-
self.set_markerfacecolor(val)
1296-
1297-
def set_mfcalt(self, val):
1298-
"""alias for set_markerfacecoloralt"""
1299-
self.set_markerfacecoloralt(val)
1300-
1301-
def set_ms(self, val):
1302-
"""alias for set_markersize"""
1303-
self.set_markersize(val)
1304-
1305-
def get_aa(self):
1306-
"""alias for get_antialiased"""
1307-
return self.get_antialiased()
1308-
1309-
def get_c(self):
1310-
"""alias for get_color"""
1311-
return self.get_color()
1312-
1313-
def get_ls(self):
1314-
"""alias for get_linestyle"""
1315-
return self.get_linestyle()
1316-
1317-
def get_lw(self):
1318-
"""alias for get_linewidth"""
1319-
return self.get_linewidth()
1320-
1321-
def get_mec(self):
1322-
"""alias for get_markeredgecolor"""
1323-
return self.get_markeredgecolor()
1324-
1325-
def get_mew(self):
1326-
"""alias for get_markeredgewidth"""
1327-
return self.get_markeredgewidth()
1328-
1329-
def get_mfc(self):
1330-
"""alias for get_markerfacecolor"""
1331-
return self.get_markerfacecolor()
1332-
1333-
def get_mfcalt(self, alt=False):
1334-
"""alias for get_markerfacecoloralt"""
1335-
return self.get_markerfacecoloralt()
1336-
1337-
def get_ms(self):
1338-
"""alias for get_markersize"""
1339-
return self.get_markersize()
1340-
13411268
def set_dash_joinstyle(self, s):
13421269
"""
13431270
Set the join style for dashed linestyles
@@ -1421,6 +1348,18 @@ def is_dashed(self):
14211348
'return True if line is dashstyle'
14221349
return self._linestyle in ('--', '-.', ':')
14231350

1351+
cbook._define_aliases(locals(), {
1352+
"antialiased": ["aa"],
1353+
"color": ["c"],
1354+
"linestyle": ["ls"],
1355+
"linewidth": ["lw"],
1356+
"markeredgecolor": ["mec"],
1357+
"markeredgewidth": ["mew"],
1358+
"markerfacecolor": ["mfc"],
1359+
"markerfacecoloralt": ["mfcalt"],
1360+
"markersize": ["ms"],
1361+
})
1362+
14241363

14251364
class VertexSelector(object):
14261365
"""

lib/matplotlib/patches.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@ def set_antialiased(self, aa):
266266
self._antialiased = aa
267267
self.stale = True
268268

269-
def set_aa(self, aa):
270-
"""alias for set_antialiased"""
271-
return self.set_antialiased(aa)
272-
273269
def _set_edgecolor(self, color):
274270
set_hatch_color = True
275271
if color is None:
@@ -294,10 +290,6 @@ def set_edgecolor(self, color):
294290
self._original_edgecolor = color
295291
self._set_edgecolor(color)
296292

297-
def set_ec(self, color):
298-
"""alias for set_edgecolor"""
299-
return self.set_edgecolor(color)
300-
301293
def _set_facecolor(self, color):
302294
if color is None:
303295
color = mpl.rcParams['patch.facecolor']
@@ -314,10 +306,6 @@ def set_facecolor(self, color):
314306
self._original_facecolor = color
315307
self._set_facecolor(color)
316308

317-
def set_fc(self, color):
318-
"""alias for set_facecolor"""
319-
return self.set_facecolor(color)
320-
321309
def set_color(self, c):
322310
"""
323311
Set both the edgecolor and the facecolor.
@@ -366,10 +354,6 @@ def set_linewidth(self, w):
366354
offset, ls, self._linewidth)
367355
self.stale = True
368356

369-
def set_lw(self, lw):
370-
"""alias for set_linewidth"""
371-
return self.set_linewidth(lw)
372-
373357
def set_linestyle(self, ls):
374358
"""
375359
Set the patch linestyle
@@ -410,10 +394,6 @@ def set_linestyle(self, ls):
410394
offset, ls, self._linewidth)
411395
self.stale = True
412396

413-
def set_ls(self, ls):
414-
"""alias for set_linestyle"""
415-
return self.set_linestyle(ls)
416-
417397
def set_fill(self, b):
418398
"""
419399
Set whether to fill the patch.
@@ -570,6 +550,14 @@ def get_path(self):
570550
def get_window_extent(self, renderer=None):
571551
return self.get_path().get_extents(self.get_transform())
572552

553+
cbook._define_aliases(locals(), {
554+
"antialiased": ["aa"],
555+
"edgecolor": ["ec"],
556+
"facecolor": ["fc"],
557+
"linewidth": ["lw"],
558+
"linestyle": ["ls"],
559+
})
560+
573561

574562
patchdoc = artist.kwdoc(Patch)
575563
for k in ('Rectangle', 'Circle', 'RegularPolygon', 'Polygon', 'Wedge', 'Arrow',

0 commit comments

Comments
 (0)