Skip to content

Commit

Permalink
Make private collection attributes singular
Browse files Browse the repository at this point in the history
  • Loading branch information
efiring committed Oct 13, 2023
1 parent e394940 commit ce900fd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 66 deletions.
86 changes: 43 additions & 43 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def __init__(self, *,
cm.ScalarMappable.__init__(self, norm, cmap)
# list of un-scaled dash patterns
# this is needed scaling the dash pattern by linewidth
self._us_linestyles = [(0, None)]
self._us_linestyle = [(0, None)]
# list of dash patterns
self._linestyles = [(0, None)]
self._linestyle = [(0, None)]
# list of unbroadcast/scaled linewidths
self._us_lw = [0]
self._linewidths = [0]
self._linewidth = [0]

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

Expand Down Expand Up @@ -380,9 +380,9 @@ def draw(self, renderer):
do_single_path_optimization = False
if (len(paths) == 1 and len(trans) <= 1 and
len(facecolors) == 1 and len(edgecolors) == 1 and
len(self._linewidths) == 1 and
all(ls[1] is None for ls in self._linestyles) and
len(self._antialiaseds) == 1 and len(self._urls) == 1 and
len(self._linewidth) == 1 and
all(ls[1] is None for ls in self._linestyle) and
len(self._antialiased) == 1 and len(self._urls) == 1 and
self.get_hatch() is None):
if len(trans):
combined_transform = transforms.Affine2D(trans[0]) + transform
Expand All @@ -401,31 +401,31 @@ def draw(self, renderer):

if do_single_path_optimization:
gc.set_foreground(tuple(edgecolors[0]))
gc.set_linewidth(self._linewidths[0])
gc.set_dashes(*self._linestyles[0])
gc.set_antialiased(self._antialiaseds[0])
gc.set_linewidth(self._linewidth[0])
gc.set_dashes(*self._linestyle[0])
gc.set_antialiased(self._antialiased[0])
gc.set_url(self._urls[0])
renderer.draw_markers(
gc, paths[0], combined_transform.frozen(),
mpath.Path(offsets), offset_trf, tuple(facecolors[0]))
else:
if self._gapcolor is not None:
# First draw paths within the gaps.
ipaths, ilinestyles = self._get_inverse_paths_linestyles()
ipaths, ilinestyles = self._get_inverse_paths_linestyle()
renderer.draw_path_collection(
gc, transform.frozen(), ipaths,
self.get_transforms(), offsets, offset_trf,
[mcolors.to_rgba("none")], self._gapcolor,
self._linewidths, ilinestyles,
self._antialiaseds, self._urls,
self._linewidth, ilinestyles,
self._antialiased, self._urls,
"screen")

renderer.draw_path_collection(
gc, transform.frozen(), paths,
self.get_transforms(), offsets, offset_trf,
self.get_facecolor(), self.get_edgecolor(),
self._linewidths, self._linestyles,
self._antialiaseds, self._urls,
self._linewidth, self._linestyle,
self._antialiased, self._urls,
"screen") # offset_position, kept for backcompat.

gc.restore()
Expand Down Expand Up @@ -584,8 +584,8 @@ def set_linewidth(self, lw):
self._us_lw = np.atleast_1d(lw)

# scale all of the dash patterns.
self._linewidths, self._linestyles = self._bcast_lwls(
self._us_lw, self._us_linestyles)
self._linewidth, self._linestyle = self._bcast_lwls(
self._us_lw, self._us_linestyle)
self.stale = True

def set_linestyle(self, ls):
Expand Down Expand Up @@ -624,11 +624,11 @@ def set_linestyle(self, ls):
raise ValueError(emsg) from err

# get the list of raw 'unscaled' dash patterns
self._us_linestyles = dashes
self._us_linestyle = dashes

# broadcast and scale the lw and dash patterns
self._linewidths, self._linestyles = self._bcast_lwls(
self._us_lw, self._us_linestyles)
self._linewidth, self._linestyle = self._bcast_lwls(
self._us_lw, self._us_linestyle)

@_docstring.interpd
def set_capstyle(self, cs):
Expand Down Expand Up @@ -732,7 +732,7 @@ def set_antialiased(self, aa):
"""
if aa is None:
aa = self._get_default_antialiased()
self._antialiaseds = np.atleast_1d(np.asarray(aa, bool))
self._antialiased = np.atleast_1d(np.asarray(aa, bool))
self.stale = True

def _get_default_antialiased(self):
Expand Down Expand Up @@ -763,7 +763,7 @@ def _set_facecolor(self, c):
if c is None:
c = self._get_default_facecolor()

self._facecolors = mcolors.to_rgba_array(c, self._alpha)
self._facecolor = mcolors.to_rgba_array(c, self._alpha)
self.stale = True

def set_facecolor(self, c):
Expand All @@ -784,13 +784,13 @@ def set_facecolor(self, c):
self._set_facecolor(c)

def get_facecolor(self):
return self._facecolors
return self._facecolor

def get_edgecolor(self):
if cbook._str_equal(self._edgecolors, 'face'):
if cbook._str_equal(self._edgecolor, 'face'):
return self.get_facecolor()
else:
return self._edgecolors
return self._edgecolor

def _get_default_edgecolor(self):
# This may be overridden in a subclass.
Expand All @@ -807,12 +807,12 @@ def _set_edgecolor(self, c):
c = 'none'
set_hatch_color = False
if cbook._str_lower_equal(c, 'face'):
self._edgecolors = 'face'
self._edgecolor = 'face'
self.stale = True
return
self._edgecolors = mcolors.to_rgba_array(c, self._alpha)
if set_hatch_color and len(self._edgecolors):
self._hatch_color = tuple(self._edgecolors[0])
self._edgecolor = mcolors.to_rgba_array(c, self._alpha)
if set_hatch_color and len(self._edgecolor):
self._hatch_color = tuple(self._edgecolor[0])
self.stale = True

def set_edgecolor(self, c):
Expand Down Expand Up @@ -852,10 +852,10 @@ def set_alpha(self, alpha):
set_alpha.__doc__ = artist.Artist._set_alpha_for_array.__doc__

def get_linewidth(self):
return self._linewidths
return self._linewidth

def get_linestyle(self):
return self._linestyles
return self._linestyle

def _set_mappable_flags(self):
"""
Expand Down Expand Up @@ -920,11 +920,11 @@ def update_scalarmappable(self):
self._mapped_colors = self.to_rgba(self._A, self._alpha)

if self._face_is_mapped:
self._facecolors = self._mapped_colors
self._facecolor = self._mapped_colors
else:
self._set_facecolor(self._original_facecolor)
if self._edge_is_mapped:
self._edgecolors = self._mapped_colors
self._edgecolor = self._mapped_colors
else:
self._set_edgecolor(self._original_edgecolor)
self.stale = True
Expand All @@ -937,17 +937,17 @@ def update_from(self, other):
"""Copy properties from other to self."""

artist.Artist.update_from(self, other)
self._antialiaseds = other._antialiaseds
self._antialiased = other._antialiased
self._mapped_colors = other._mapped_colors
self._edge_is_mapped = other._edge_is_mapped
self._original_edgecolor = other._original_edgecolor
self._edgecolors = other._edgecolors
self._edgecolor = other._edgecolor
self._face_is_mapped = other._face_is_mapped
self._original_facecolor = other._original_facecolor
self._facecolors = other._facecolors
self._linewidths = other._linewidths
self._linestyles = other._linestyles
self._us_linestyles = other._us_linestyles
self._facecolor = other._facecolor
self._linewidth = other._linewidth
self._linestyle = other._linestyle
self._us_linestyle = other._us_linestyle
self._pickradius = other._pickradius
self._hatch = other._hatch

Expand Down Expand Up @@ -1465,7 +1465,7 @@ def set_color(self, c):
set_colors = set_color

def get_color(self):
return self._edgecolors
return self._edgecolor

get_colors = get_color # for compatibility with old versions

Expand Down Expand Up @@ -1499,7 +1499,7 @@ def _set_gapcolor(self, gapcolor):
def get_gapcolor(self):
return self._gapcolor

def _get_inverse_paths_linestyles(self):
def _get_inverse_paths_linestyle(self):
"""
Returns the path and pattern for the gaps in the non-solid lines.
Expand All @@ -1512,7 +1512,7 @@ def _get_inverse_paths_linestyles(self):
if ls == (0, None) else
(path, mlines._get_inverse_dash_pattern(*ls))
for (path, ls) in
zip(self._paths, itertools.cycle(self._linestyles))]
zip(self._paths, itertools.cycle(self._linestyle))]

return zip(*path_patterns)

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

self.update_scalarmappable()
colors = self._facecolors[triangles]
colors = self._facecolor[triangles]

gc = renderer.new_gc()
self._set_gc_clip(gc)
Expand Down Expand Up @@ -2179,7 +2179,7 @@ def draw(self, renderer):
coordinates, offsets, offset_trf,
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
self.get_facecolor().reshape((-1, 4)),
self._antialiased, self.get_edgecolors().reshape((-1, 4)))
self._antialiased, self.get_edgecolor().reshape((-1, 4)))
gc.restore()
renderer.close_group(self.__class__.__name__)
self.stale = False
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/legend_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def get_numpoints(self, legend):

def _default_update_prop(self, legend_handle, orig_handle):
lw = orig_handle.get_linewidths()[0]
dashes = orig_handle._us_linestyles[0]
dashes = orig_handle._us_linestyle[0]
color = orig_handle.get_colors()[0]
legend_handle.set_color(color)
legend_handle.set_linestyle(dashes)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def __init__(self, xdata, ydata, *,
self.set_solid_capstyle(solid_capstyle)
self.set_solid_joinstyle(solid_joinstyle)

self._linestyles = None
self._linestyle = None
self._drawstyle = None
self._linewidth = linewidth
self._unscaled_dash_pattern = (0, None) # offset, dash
Expand Down
42 changes: 21 additions & 21 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def get_edgecolor(self):
# We need this check here to make sure we do not double-apply the depth
# based alpha shading when the edge color is "face" which means the
# edge colour should be identical to the face colour.
if cbook._str_equal(self._edgecolors, 'face'):
if cbook._str_equal(self._edgecolor, 'face'):
return self.get_facecolor()
return self._maybe_depth_shade_and_sort_colors(super().get_edgecolor())

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

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

def get_depthshade(self):
return self._depthshade
Expand Down Expand Up @@ -763,8 +763,8 @@ def do_3d_projection(self):
if len(self._sizes3d) > 1:
self._sizes = self._sizes3d[z_markers_idx]

if len(self._linewidths3d) > 1:
self._linewidths = self._linewidths3d[z_markers_idx]
if len(self._linewidth3d) > 1:
self._linewidth = self._linewidth3d[z_markers_idx]

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

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

Expand Down Expand Up @@ -890,8 +890,8 @@ def __init__(self, verts, *args, zsort='average', shade=False,
Notes
-----
Note that this class does a bit of magic with the _facecolors
and _edgecolors properties.
Note that this class does a bit of magic with the _facecolor
and _edgecolor properties.
"""
if shade:
normals = _generate_normals(verts)
Expand Down Expand Up @@ -1009,9 +1009,9 @@ def do_3d_projection(self):
# passed in) and sort the 2D version by view depth.
self.update_scalarmappable()
if self._face_is_mapped:
self._facecolor3d = self._facecolors
self._facecolor3d = self._facecolor
if self._edge_is_mapped:
self._edgecolor3d = self._edgecolors
self._edgecolor3d = self._edgecolor
txs, tys, tzs = proj3d._proj_transform_vec(self._vec, self.axes.M)
xyzlist = [(txs[sl], tys[sl], tzs[sl]) for sl in self._segslices]

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

_, segments_2d, self._facecolors2d, self._edgecolors2d, idxs = \
_, segments_2d, self._facecolor2d, self._edgecolor2d, idxs = \
zip(*z_segments_2d)
else:
segments_2d = []
self._facecolors2d = np.empty((0, 4))
self._edgecolors2d = np.empty((0, 4))
self._facecolor2d = np.empty((0, 4))
self._edgecolor2d = np.empty((0, 4))
idxs = []

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

if len(self._edgecolor3d) != len(cface):
self._edgecolors2d = self._edgecolor3d
self._edgecolor2d = self._edgecolor3d

# Return zorder value
if self._sort_zpos is not None:
Expand Down Expand Up @@ -1083,27 +1083,27 @@ def set_alpha(self, alpha):
except (AttributeError, TypeError, IndexError):
pass
try:
self._edgecolors = mcolors.to_rgba_array(
self._edgecolor = mcolors.to_rgba_array(
self._edgecolor3d, self._alpha)
except (AttributeError, TypeError, IndexError):
pass
self.stale = True

def get_facecolor(self):
# docstring inherited
# self._facecolors2d is not initialized until do_3d_projection
if not hasattr(self, '_facecolors2d'):
# self._facecolor2d is not initialized until do_3d_projection
if not hasattr(self, '_facecolor2d'):
self.axes.M = self.axes.get_proj()
self.do_3d_projection()
return np.asarray(self._facecolors2d)
return np.asarray(self._facecolor2d)

def get_edgecolor(self):
# docstring inherited
# self._edgecolors2d is not initialized until do_3d_projection
if not hasattr(self, '_edgecolors2d'):
# self._edgecolor2d is not initialized until do_3d_projection
if not hasattr(self, '_edgecolor2d'):
self.axes.M = self.axes.get_proj()
self.do_3d_projection()
return np.asarray(self._edgecolors2d)
return np.asarray(self._edgecolor2d)


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

0 comments on commit ce900fd

Please sign in to comment.