diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index a4d97374c45f..acaf2b0f388e 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -401,9 +401,9 @@ def get_extent_offsets(self, renderer): yoffsets = yoffsets - ydescent - return width + 2 * pad, height + 2 * pad, \ - xdescent + pad, ydescent + pad, \ - list(zip(xoffsets, yoffsets)) + return (width + 2 * pad, height + 2 * pad, + xdescent + pad, ydescent + pad, + list(zip(xoffsets, yoffsets))) class HPacker(PackerBase): @@ -479,9 +479,9 @@ def get_extent_offsets(self, renderer): xdescent = whd_list[0][2] xoffsets = xoffsets - xdescent - return width + 2 * pad, height + 2 * pad, \ - xdescent + pad, ydescent + pad, \ - list(zip(xoffsets, yoffsets)) + return (width + 2 * pad, height + 2 * pad, + xdescent + pad, ydescent + pad, + list(zip(xoffsets, yoffsets))) class PaddedBox(OffsetBox): diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py index 63a7208bf5ff..7654a2ae1115 100644 --- a/lib/matplotlib/textpath.py +++ b/lib/matplotlib/textpath.py @@ -166,8 +166,7 @@ def get_text_path(self, prop, s, ismath=False, usetex=False): def get_glyphs_with_font(self, font, s, glyph_map=None, return_new_glyphs_only=False): """ - convert the string *s* to vertices and codes using the - provided ttf font. + Convert string *s* to vertices and codes using the provided ttf font. """ # Mostly copied from backend_svg.py. @@ -201,13 +200,13 @@ def get_glyphs_with_font(self, font, s, glyph_map=None, kern = 0 glyph = font.load_char(ccode, flags=LOAD_NO_HINTING) - horiz_advance = (glyph.linearHoriAdvance / 65536.0) + horiz_advance = glyph.linearHoriAdvance / 65536 char_id = self._get_char_id(font, ccode) if char_id not in glyph_map: glyph_map_new[char_id] = self.glyph_to_path(font) - currx += (kern / 64.0) + currx += kern / 64 xpositions.append(currx) glyph_ids.append(char_id) @@ -222,7 +221,7 @@ def get_glyphs_with_font(self, font, s, glyph_map=None, rects = [] return (list(zip(glyph_ids, xpositions, ypositions, sizes)), - glyph_map_new, rects) + glyph_map_new, rects) def get_glyphs_mathtext(self, prop, s, glyph_map=None, return_new_glyphs_only=False): diff --git a/lib/mpl_toolkits/axisartist/clip_path.py b/lib/mpl_toolkits/axisartist/clip_path.py index 8507b09b0750..807f5d15f7c7 100644 --- a/lib/mpl_toolkits/axisartist/clip_path.py +++ b/lib/mpl_toolkits/axisartist/clip_path.py @@ -26,16 +26,8 @@ def clip(xlines, ylines, x0, clip="right", xdir=True, ydir=True): _pos_angles = [] - if xdir: - xsign = 1 - else: - xsign = -1 - - if ydir: - ysign = 1 - else: - ysign = -1 - + xsign = 1 if xdir else -1 + ysign = 1 if ydir else -1 for x, y in zip(xlines, ylines): @@ -46,7 +38,6 @@ def clip(xlines, ylines, x0, clip="right", xdir=True, ydir=True): b = (x > x0).astype("i") db = b[1:] - b[:-1] - if b[0]: ns = 0 else: @@ -56,7 +47,7 @@ def clip(xlines, ylines, x0, clip="right", xdir=True, ydir=True): c = db[i] if c == -1: dx = (x0 - x[i]) - dy = (y[i+1] - y[i]) * (dx/ (x[i+1] - x[i])) + dy = (y[i+1] - y[i]) * (dx / (x[i+1] - x[i])) y0 = y[i] + dy clipped_xlines.append(np.concatenate([segx, x[ns:i+1], [x0]])) clipped_ylines.append(np.concatenate([segy, y[ns:i+1], [y0]])) @@ -88,9 +79,6 @@ def clip(xlines, ylines, x0, clip="right", xdir=True, ydir=True): clipped_xlines.append(np.concatenate([segx, x[ns:]])) clipped_ylines.append(np.concatenate([segy, y[ns:]])) - #clipped_pos_angles.append(_pos_angles) - - return clipped_xlines, clipped_ylines, _pos_angles @@ -121,15 +109,13 @@ def clip_line_to_rect(xline, yline, bbox): # ly3, lx3, c_top_ = clip(ly2, lx2, y1, clip="right") # ly4, lx4, c_bottom_ = clip(ly3, lx3, y0, clip="left") - #c_left = [((x, y), (a+90)%180-180) for (x, y, a) in c_left_ \ - # if bbox.containsy(y)] - c_left = [((x, y), (a+90)%180-90) for (x, y, a) in c_left_ + c_left = [((x, y), (a + 90) % 180 - 90) for x, y, a in c_left_ if bbox.containsy(y)] - c_bottom = [((x, y), (90 - a)%180) for (y, x, a) in c_bottom_ + c_bottom = [((x, y), (90 - a) % 180) for y, x, a in c_bottom_ if bbox.containsx(x)] - c_right = [((x, y), (a+90)%180+90) for (x, y, a) in c_right_ + c_right = [((x, y), (a + 90) % 180 + 90) for x, y, a in c_right_ if bbox.containsy(y)] - c_top = [((x, y), (90 - a)%180+180) for (y, x, a) in c_top_ + c_top = [((x, y), (90 - a) % 180 + 180) for y, x, a in c_top_ if bbox.containsx(x)] return list(zip(lx4, ly4)), [c_left, c_bottom, c_right, c_top] diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 038616f62856..f6d6c399b2e3 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -15,9 +15,9 @@ import six from six.moves import map, zip, reduce +from collections import defaultdict import math import warnings -from collections import defaultdict import numpy as np @@ -210,17 +210,21 @@ def _init_axis(self): ax.init3d() def get_children(self): - return [self.zaxis, ] + super().get_children() + return [self.zaxis] + super().get_children() def _get_axis_list(self): return super()._get_axis_list() + (self.zaxis, ) def unit_cube(self, vals=None): minx, maxx, miny, maxy, minz, maxz = vals or self.get_w_lims() - xs, ys, zs = ([minx, maxx, maxx, minx, minx, maxx, maxx, minx], - [miny, miny, maxy, maxy, miny, miny, maxy, maxy], - [minz, minz, minz, minz, maxz, maxz, maxz, maxz]) - return list(zip(xs, ys, zs)) + return [(minx, miny, minz), + (maxx, miny, minz), + (maxx, maxy, minz), + (minx, maxy, minz), + (minx, miny, maxz), + (maxx, miny, maxz), + (maxx, maxy, maxz), + (minx, maxy, maxz)] def tunit_cube(self, vals=None, M=None): if M is None: diff --git a/lib/mpl_toolkits/mplot3d/axis3d.py b/lib/mpl_toolkits/mplot3d/axis3d.py index 50b81df9125e..4093e9bd81e0 100644 --- a/lib/mpl_toolkits/mplot3d/axis3d.py +++ b/lib/mpl_toolkits/mplot3d/axis3d.py @@ -288,7 +288,7 @@ def draw(self, renderer): ax_scale = self.axes.bbox.size / self.figure.bbox.size ax_inches = np.multiply(ax_scale, self.figure.get_size_inches()) ax_points_estimate = sum(72. * ax_inches) - deltas_per_point = 48. / ax_points_estimate + deltas_per_point = 48 / ax_points_estimate default_offset = 21. labeldeltas = ( (self.labelpad + default_offset) * deltas_per_point * deltas) @@ -305,15 +305,14 @@ def draw(self, renderer): self.label.set_ha(info['label']['ha']) self.label.draw(renderer) - # Draw Offset text # Which of the two edge points do we want to # use for locating the offset text? - if juggled[2] == 2 : + if juggled[2] == 2: outeredgep = edgep1 outerindex = 0 - else : + else: outeredgep = edgep2 outerindex = 1 @@ -321,8 +320,8 @@ def draw(self, renderer): pos = move_from_center(pos, centers, labeldeltas, axmask) olx, oly, olz = proj3d.proj_transform( pos[0], pos[1], pos[2], renderer.M) - self.offsetText.set_text( self.major.formatter.get_offset() ) - self.offsetText.set_position( (olx, oly) ) + self.offsetText.set_text(self.major.formatter.get_offset()) + self.offsetText.set_position((olx, oly)) angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx))) self.offsetText.set_rotation(angle) # Must set rotation mode to "anchor" so that @@ -344,29 +343,29 @@ def draw(self, renderer): # Three-letters (e.g., TFT, FTT) are short-hand for the array of bools # from the variable 'highs'. # --------------------------------------------------------------------- - if centpt[info['tickdir']] > peparray[info['tickdir'], outerindex] : + if centpt[info['tickdir']] > peparray[info['tickdir'], outerindex]: # if FT and if highs has an even number of Trues if (centpt[index] <= peparray[index, outerindex] - and ((len(highs.nonzero()[0]) % 2) == 0)) : + and len(highs.nonzero()[0]) % 2 == 0): # Usually, this means align right, except for the FTT case, # in which offset for axis 1 and 2 are aligned left. - if highs.tolist() == [False, True, True] and index in (1, 2) : + if highs.tolist() == [False, True, True] and index in (1, 2): align = 'left' - else : + else: align = 'right' - else : + else: # The FF case align = 'left' - else : + else: # if TF and if highs has an even number of Trues if (centpt[index] > peparray[index, outerindex] - and ((len(highs.nonzero()[0]) % 2) == 0)) : + and len(highs.nonzero()[0]) % 2 == 0): # Usually mean align left, except if it is axis 2 - if index == 2 : + if index == 2: align = 'right' - else : + else: align = 'left' - else : + else: # The TT case align = 'right' @@ -385,7 +384,7 @@ def draw(self, renderer): # Grid points at end of the other plane xyz2 = copy.deepcopy(xyz0) - newindex = (index + 2) % 3 + newindex = (index + 2) % 3 newval = get_flip_min_max(xyz2[0], newindex, mins, maxs) for i in range(len(majorLocs)): xyz2[i][newindex] = newval @@ -461,7 +460,7 @@ def set_view_interval(self, vmin, vmax, ignore=False): # TODO: Get this to work properly when mplot3d supports # the transforms framework. - def get_tightbbox(self, renderer) : + def get_tightbbox(self, renderer): # Currently returns None so that Axis.get_tightbbox # doesn't return junk info. return None