Skip to content

Commit ce900fd

Browse files
committed
Make private collection attributes singular
1 parent e394940 commit ce900fd

File tree

4 files changed

+66
-66
lines changed

4 files changed

+66
-66
lines changed

lib/matplotlib/collections.py

+43-43
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ def __init__(self, *,
156156
cm.ScalarMappable.__init__(self, norm, cmap)
157157
# list of un-scaled dash patterns
158158
# this is needed scaling the dash pattern by linewidth
159-
self._us_linestyles = [(0, None)]
159+
self._us_linestyle = [(0, None)]
160160
# list of dash patterns
161-
self._linestyles = [(0, None)]
161+
self._linestyle = [(0, None)]
162162
# list of unbroadcast/scaled linewidths
163163
self._us_lw = [0]
164-
self._linewidths = [0]
164+
self._linewidth = [0]
165165

166166
self._gapcolor = None # Currently only used by LineCollection.
167167

@@ -380,9 +380,9 @@ def draw(self, renderer):
380380
do_single_path_optimization = False
381381
if (len(paths) == 1 and len(trans) <= 1 and
382382
len(facecolors) == 1 and len(edgecolors) == 1 and
383-
len(self._linewidths) == 1 and
384-
all(ls[1] is None for ls in self._linestyles) and
385-
len(self._antialiaseds) == 1 and len(self._urls) == 1 and
383+
len(self._linewidth) == 1 and
384+
all(ls[1] is None for ls in self._linestyle) and
385+
len(self._antialiased) == 1 and len(self._urls) == 1 and
386386
self.get_hatch() is None):
387387
if len(trans):
388388
combined_transform = transforms.Affine2D(trans[0]) + transform
@@ -401,31 +401,31 @@ def draw(self, renderer):
401401

402402
if do_single_path_optimization:
403403
gc.set_foreground(tuple(edgecolors[0]))
404-
gc.set_linewidth(self._linewidths[0])
405-
gc.set_dashes(*self._linestyles[0])
406-
gc.set_antialiased(self._antialiaseds[0])
404+
gc.set_linewidth(self._linewidth[0])
405+
gc.set_dashes(*self._linestyle[0])
406+
gc.set_antialiased(self._antialiased[0])
407407
gc.set_url(self._urls[0])
408408
renderer.draw_markers(
409409
gc, paths[0], combined_transform.frozen(),
410410
mpath.Path(offsets), offset_trf, tuple(facecolors[0]))
411411
else:
412412
if self._gapcolor is not None:
413413
# First draw paths within the gaps.
414-
ipaths, ilinestyles = self._get_inverse_paths_linestyles()
414+
ipaths, ilinestyles = self._get_inverse_paths_linestyle()
415415
renderer.draw_path_collection(
416416
gc, transform.frozen(), ipaths,
417417
self.get_transforms(), offsets, offset_trf,
418418
[mcolors.to_rgba("none")], self._gapcolor,
419-
self._linewidths, ilinestyles,
420-
self._antialiaseds, self._urls,
419+
self._linewidth, ilinestyles,
420+
self._antialiased, self._urls,
421421
"screen")
422422

423423
renderer.draw_path_collection(
424424
gc, transform.frozen(), paths,
425425
self.get_transforms(), offsets, offset_trf,
426426
self.get_facecolor(), self.get_edgecolor(),
427-
self._linewidths, self._linestyles,
428-
self._antialiaseds, self._urls,
427+
self._linewidth, self._linestyle,
428+
self._antialiased, self._urls,
429429
"screen") # offset_position, kept for backcompat.
430430

431431
gc.restore()
@@ -584,8 +584,8 @@ def set_linewidth(self, lw):
584584
self._us_lw = np.atleast_1d(lw)
585585

586586
# scale all of the dash patterns.
587-
self._linewidths, self._linestyles = self._bcast_lwls(
588-
self._us_lw, self._us_linestyles)
587+
self._linewidth, self._linestyle = self._bcast_lwls(
588+
self._us_lw, self._us_linestyle)
589589
self.stale = True
590590

591591
def set_linestyle(self, ls):
@@ -624,11 +624,11 @@ def set_linestyle(self, ls):
624624
raise ValueError(emsg) from err
625625

626626
# get the list of raw 'unscaled' dash patterns
627-
self._us_linestyles = dashes
627+
self._us_linestyle = dashes
628628

629629
# broadcast and scale the lw and dash patterns
630-
self._linewidths, self._linestyles = self._bcast_lwls(
631-
self._us_lw, self._us_linestyles)
630+
self._linewidth, self._linestyle = self._bcast_lwls(
631+
self._us_lw, self._us_linestyle)
632632

633633
@_docstring.interpd
634634
def set_capstyle(self, cs):
@@ -732,7 +732,7 @@ def set_antialiased(self, aa):
732732
"""
733733
if aa is None:
734734
aa = self._get_default_antialiased()
735-
self._antialiaseds = np.atleast_1d(np.asarray(aa, bool))
735+
self._antialiased = np.atleast_1d(np.asarray(aa, bool))
736736
self.stale = True
737737

738738
def _get_default_antialiased(self):
@@ -763,7 +763,7 @@ def _set_facecolor(self, c):
763763
if c is None:
764764
c = self._get_default_facecolor()
765765

766-
self._facecolors = mcolors.to_rgba_array(c, self._alpha)
766+
self._facecolor = mcolors.to_rgba_array(c, self._alpha)
767767
self.stale = True
768768

769769
def set_facecolor(self, c):
@@ -784,13 +784,13 @@ def set_facecolor(self, c):
784784
self._set_facecolor(c)
785785

786786
def get_facecolor(self):
787-
return self._facecolors
787+
return self._facecolor
788788

789789
def get_edgecolor(self):
790-
if cbook._str_equal(self._edgecolors, 'face'):
790+
if cbook._str_equal(self._edgecolor, 'face'):
791791
return self.get_facecolor()
792792
else:
793-
return self._edgecolors
793+
return self._edgecolor
794794

795795
def _get_default_edgecolor(self):
796796
# This may be overridden in a subclass.
@@ -807,12 +807,12 @@ def _set_edgecolor(self, c):
807807
c = 'none'
808808
set_hatch_color = False
809809
if cbook._str_lower_equal(c, 'face'):
810-
self._edgecolors = 'face'
810+
self._edgecolor = 'face'
811811
self.stale = True
812812
return
813-
self._edgecolors = mcolors.to_rgba_array(c, self._alpha)
814-
if set_hatch_color and len(self._edgecolors):
815-
self._hatch_color = tuple(self._edgecolors[0])
813+
self._edgecolor = mcolors.to_rgba_array(c, self._alpha)
814+
if set_hatch_color and len(self._edgecolor):
815+
self._hatch_color = tuple(self._edgecolor[0])
816816
self.stale = True
817817

818818
def set_edgecolor(self, c):
@@ -852,10 +852,10 @@ def set_alpha(self, alpha):
852852
set_alpha.__doc__ = artist.Artist._set_alpha_for_array.__doc__
853853

854854
def get_linewidth(self):
855-
return self._linewidths
855+
return self._linewidth
856856

857857
def get_linestyle(self):
858-
return self._linestyles
858+
return self._linestyle
859859

860860
def _set_mappable_flags(self):
861861
"""
@@ -920,11 +920,11 @@ def update_scalarmappable(self):
920920
self._mapped_colors = self.to_rgba(self._A, self._alpha)
921921

922922
if self._face_is_mapped:
923-
self._facecolors = self._mapped_colors
923+
self._facecolor = self._mapped_colors
924924
else:
925925
self._set_facecolor(self._original_facecolor)
926926
if self._edge_is_mapped:
927-
self._edgecolors = self._mapped_colors
927+
self._edgecolor = self._mapped_colors
928928
else:
929929
self._set_edgecolor(self._original_edgecolor)
930930
self.stale = True
@@ -937,17 +937,17 @@ def update_from(self, other):
937937
"""Copy properties from other to self."""
938938

939939
artist.Artist.update_from(self, other)
940-
self._antialiaseds = other._antialiaseds
940+
self._antialiased = other._antialiased
941941
self._mapped_colors = other._mapped_colors
942942
self._edge_is_mapped = other._edge_is_mapped
943943
self._original_edgecolor = other._original_edgecolor
944-
self._edgecolors = other._edgecolors
944+
self._edgecolor = other._edgecolor
945945
self._face_is_mapped = other._face_is_mapped
946946
self._original_facecolor = other._original_facecolor
947-
self._facecolors = other._facecolors
948-
self._linewidths = other._linewidths
949-
self._linestyles = other._linestyles
950-
self._us_linestyles = other._us_linestyles
947+
self._facecolor = other._facecolor
948+
self._linewidth = other._linewidth
949+
self._linestyle = other._linestyle
950+
self._us_linestyle = other._us_linestyle
951951
self._pickradius = other._pickradius
952952
self._hatch = other._hatch
953953

@@ -1465,7 +1465,7 @@ def set_color(self, c):
14651465
set_colors = set_color
14661466

14671467
def get_color(self):
1468-
return self._edgecolors
1468+
return self._edgecolor
14691469

14701470
get_colors = get_color # for compatibility with old versions
14711471

@@ -1499,7 +1499,7 @@ def _set_gapcolor(self, gapcolor):
14991499
def get_gapcolor(self):
15001500
return self._gapcolor
15011501

1502-
def _get_inverse_paths_linestyles(self):
1502+
def _get_inverse_paths_linestyle(self):
15031503
"""
15041504
Returns the path and pattern for the gaps in the non-solid lines.
15051505
@@ -1512,7 +1512,7 @@ def _get_inverse_paths_linestyles(self):
15121512
if ls == (0, None) else
15131513
(path, mlines._get_inverse_dash_pattern(*ls))
15141514
for (path, ls) in
1515-
zip(self._paths, itertools.cycle(self._linestyles))]
1515+
zip(self._paths, itertools.cycle(self._linestyle))]
15161516

15171517
return zip(*path_patterns)
15181518

@@ -1914,7 +1914,7 @@ def draw(self, renderer):
19141914
verts = np.stack((tri.x[triangles], tri.y[triangles]), axis=-1)
19151915

19161916
self.update_scalarmappable()
1917-
colors = self._facecolors[triangles]
1917+
colors = self._facecolor[triangles]
19181918

19191919
gc = renderer.new_gc()
19201920
self._set_gc_clip(gc)
@@ -2179,7 +2179,7 @@ def draw(self, renderer):
21792179
coordinates, offsets, offset_trf,
21802180
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
21812181
self.get_facecolor().reshape((-1, 4)),
2182-
self._antialiased, self.get_edgecolors().reshape((-1, 4)))
2182+
self._antialiased, self.get_edgecolor().reshape((-1, 4)))
21832183
gc.restore()
21842184
renderer.close_group(self.__class__.__name__)
21852185
self.stale = False

lib/matplotlib/legend_handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def get_numpoints(self, legend):
407407

408408
def _default_update_prop(self, legend_handle, orig_handle):
409409
lw = orig_handle.get_linewidths()[0]
410-
dashes = orig_handle._us_linestyles[0]
410+
dashes = orig_handle._us_linestyle[0]
411411
color = orig_handle.get_colors()[0]
412412
legend_handle.set_color(color)
413413
legend_handle.set_linestyle(dashes)

lib/matplotlib/lines.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def __init__(self, xdata, ydata, *,
362362
self.set_solid_capstyle(solid_capstyle)
363363
self.set_solid_joinstyle(solid_joinstyle)
364364

365-
self._linestyles = None
365+
self._linestyle = None
366366
self._drawstyle = None
367367
self._linewidth = linewidth
368368
self._unscaled_dash_pattern = (0, None) # offset, dash

lib/mpl_toolkits/mplot3d/art3d.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def get_edgecolor(self):
633633
# We need this check here to make sure we do not double-apply the depth
634634
# based alpha shading when the edge color is "face" which means the
635635
# edge colour should be identical to the face colour.
636-
if cbook._str_equal(self._edgecolors, 'face'):
636+
if cbook._str_equal(self._edgecolor, 'face'):
637637
return self.get_facecolor()
638638
return self._maybe_depth_shade_and_sort_colors(super().get_edgecolor())
639639

@@ -709,7 +709,7 @@ def set_3d_properties(self, zs, zdir):
709709
#
710710
# Grab the current sizes and linewidths to preserve them.
711711
self._sizes3d = self._sizes
712-
self._linewidths3d = np.array(self._linewidths)
712+
self._linewidth3d = np.array(self._linewidth)
713713
xs, ys, zs = self._offsets3d
714714

715715
# Sort the points based on z coordinates
@@ -727,7 +727,7 @@ def set_sizes(self, sizes, dpi=72.0):
727727
def set_linewidth(self, lw):
728728
super().set_linewidth(lw)
729729
if not self._in_draw:
730-
self._linewidths3d = np.array(self._linewidths)
730+
self._linewidth3d = np.array(self._linewidth)
731731

732732
def get_depthshade(self):
733733
return self._depthshade
@@ -763,8 +763,8 @@ def do_3d_projection(self):
763763
if len(self._sizes3d) > 1:
764764
self._sizes = self._sizes3d[z_markers_idx]
765765

766-
if len(self._linewidths3d) > 1:
767-
self._linewidths = self._linewidths3d[z_markers_idx]
766+
if len(self._linewidth3d) > 1:
767+
self._linewidth = self._linewidth3d[z_markers_idx]
768768

769769
PathCollection.set_offsets(self, np.column_stack((vxs, vys)))
770770

@@ -809,7 +809,7 @@ def get_edgecolor(self):
809809
# We need this check here to make sure we do not double-apply the depth
810810
# based alpha shading when the edge color is "face" which means the
811811
# edge colour should be identical to the face colour.
812-
if cbook._str_equal(self._edgecolors, 'face'):
812+
if cbook._str_equal(self._edgecolor, 'face'):
813813
return self.get_facecolor()
814814
return self._maybe_depth_shade_and_sort_colors(super().get_edgecolor())
815815

@@ -890,8 +890,8 @@ def __init__(self, verts, *args, zsort='average', shade=False,
890890
891891
Notes
892892
-----
893-
Note that this class does a bit of magic with the _facecolors
894-
and _edgecolors properties.
893+
Note that this class does a bit of magic with the _facecolor
894+
and _edgecolor properties.
895895
"""
896896
if shade:
897897
normals = _generate_normals(verts)
@@ -1009,9 +1009,9 @@ def do_3d_projection(self):
10091009
# passed in) and sort the 2D version by view depth.
10101010
self.update_scalarmappable()
10111011
if self._face_is_mapped:
1012-
self._facecolor3d = self._facecolors
1012+
self._facecolor3d = self._facecolor
10131013
if self._edge_is_mapped:
1014-
self._edgecolor3d = self._edgecolors
1014+
self._edgecolor3d = self._edgecolor
10151015
txs, tys, tzs = proj3d._proj_transform_vec(self._vec, self.axes.M)
10161016
xyzlist = [(txs[sl], tys[sl], tzs[sl]) for sl in self._segslices]
10171017

@@ -1034,12 +1034,12 @@ def do_3d_projection(self):
10341034
in enumerate(zip(xyzlist, cface, cedge))),
10351035
key=lambda x: x[0], reverse=True)
10361036

1037-
_, segments_2d, self._facecolors2d, self._edgecolors2d, idxs = \
1037+
_, segments_2d, self._facecolor2d, self._edgecolor2d, idxs = \
10381038
zip(*z_segments_2d)
10391039
else:
10401040
segments_2d = []
1041-
self._facecolors2d = np.empty((0, 4))
1042-
self._edgecolors2d = np.empty((0, 4))
1041+
self._facecolor2d = np.empty((0, 4))
1042+
self._edgecolor2d = np.empty((0, 4))
10431043
idxs = []
10441044

10451045
if self._codes3d is not None:
@@ -1049,7 +1049,7 @@ def do_3d_projection(self):
10491049
PolyCollection.set_verts(self, segments_2d, self._closed)
10501050

10511051
if len(self._edgecolor3d) != len(cface):
1052-
self._edgecolors2d = self._edgecolor3d
1052+
self._edgecolor2d = self._edgecolor3d
10531053

10541054
# Return zorder value
10551055
if self._sort_zpos is not None:
@@ -1083,27 +1083,27 @@ def set_alpha(self, alpha):
10831083
except (AttributeError, TypeError, IndexError):
10841084
pass
10851085
try:
1086-
self._edgecolors = mcolors.to_rgba_array(
1086+
self._edgecolor = mcolors.to_rgba_array(
10871087
self._edgecolor3d, self._alpha)
10881088
except (AttributeError, TypeError, IndexError):
10891089
pass
10901090
self.stale = True
10911091

10921092
def get_facecolor(self):
10931093
# docstring inherited
1094-
# self._facecolors2d is not initialized until do_3d_projection
1095-
if not hasattr(self, '_facecolors2d'):
1094+
# self._facecolor2d is not initialized until do_3d_projection
1095+
if not hasattr(self, '_facecolor2d'):
10961096
self.axes.M = self.axes.get_proj()
10971097
self.do_3d_projection()
1098-
return np.asarray(self._facecolors2d)
1098+
return np.asarray(self._facecolor2d)
10991099

11001100
def get_edgecolor(self):
11011101
# docstring inherited
1102-
# self._edgecolors2d is not initialized until do_3d_projection
1103-
if not hasattr(self, '_edgecolors2d'):
1102+
# self._edgecolor2d is not initialized until do_3d_projection
1103+
if not hasattr(self, '_edgecolor2d'):
11041104
self.axes.M = self.axes.get_proj()
11051105
self.do_3d_projection()
1106-
return np.asarray(self._edgecolors2d)
1106+
return np.asarray(self._edgecolor2d)
11071107

11081108

11091109
def poly_collection_2d_to_3d(col, zs=0, zdir='z'):

0 commit comments

Comments
 (0)