diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index 49f87edc3907..42970a9b26df 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -1114,22 +1114,14 @@ def _make_paths_from_contour_generator(self): """Compute ``paths`` using C extension.""" if self._paths is not None: return self._paths - paths = [] + cg = self._contour_generator empty_path = Path(np.empty((0, 2))) - if self.filled: - lowers, uppers = self._get_lowers_and_uppers() - for level, level_upper in zip(lowers, uppers): - vertices, kinds = \ - self._contour_generator.create_filled_contour( - level, level_upper) - paths.append(Path(np.concatenate(vertices), np.concatenate(kinds)) - if len(vertices) else empty_path) - else: - for level in self.levels: - vertices, kinds = self._contour_generator.create_contour(level) - paths.append(Path(np.concatenate(vertices), np.concatenate(kinds)) - if len(vertices) else empty_path) - return paths + vertices_and_codes = ( + map(cg.create_filled_contour, *self._get_lowers_and_uppers()) + if self.filled else + map(cg.create_contour, self.levels)) + return [Path(np.concatenate(vs), np.concatenate(cs)) if len(vs) else empty_path + for vs, cs in vertices_and_codes] def _get_lowers_and_uppers(self): """ diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index b2177e5087bc..ee2032b17be3 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -125,64 +125,28 @@ def glyph_name_or_index(self): # Opcode argument parsing # -# Each of the following functions takes a Dvi object and delta, -# which is the difference between the opcode and the minimum opcode -# with the same meaning. Dvi opcodes often encode the number of -# argument bytes in this delta. - -def _arg_raw(dvi, delta): - """Return *delta* without reading anything more from the dvi file.""" - return delta - - -def _arg(nbytes, signed, dvi, _): - """ - Read *nbytes* bytes, returning the bytes interpreted as a signed integer - if *signed* is true, unsigned otherwise. - """ - return dvi._arg(nbytes, signed) - - -def _arg_slen(dvi, delta): - """ - Read *delta* bytes, returning None if *delta* is zero, and the bytes - interpreted as a signed integer otherwise. - """ - if delta == 0: - return None - return dvi._arg(delta, True) - - -def _arg_slen1(dvi, delta): - """ - Read *delta*+1 bytes, returning the bytes interpreted as signed. - """ - return dvi._arg(delta + 1, True) - - -def _arg_ulen1(dvi, delta): - """ - Read *delta*+1 bytes, returning the bytes interpreted as unsigned. - """ - return dvi._arg(delta + 1, False) - - -def _arg_olen1(dvi, delta): - """ - Read *delta*+1 bytes, returning the bytes interpreted as - unsigned integer for 0<=*delta*<3 and signed if *delta*==3. - """ - return dvi._arg(delta + 1, delta == 3) - - -_arg_mapping = dict(raw=_arg_raw, - u1=partial(_arg, 1, False), - u4=partial(_arg, 4, False), - s4=partial(_arg, 4, True), - slen=_arg_slen, - olen1=_arg_olen1, - slen1=_arg_slen1, - ulen1=_arg_ulen1) +# Each of the following functions takes a Dvi object and delta, which is the +# difference between the opcode and the minimum opcode with the same meaning. +# Dvi opcodes often encode the number of argument bytes in this delta. +_arg_mapping = dict( + # raw: Return delta as is. + raw=lambda dvi, delta: delta, + # u1: Read 1 byte as an unsigned number. + u1=lambda dvi, delta: dvi._arg(1, signed=False), + # u4: Read 4 bytes as an unsigned number. + u4=lambda dvi, delta: dvi._arg(4, signed=False), + # s4: Read 4 bytes as a signed number. + s4=lambda dvi, delta: dvi._arg(4, signed=True), + # slen: Read delta bytes as a signed number, or None if delta is None. + slen=lambda dvi, delta: dvi._arg(delta, signed=True) if delta else None, + # slen1: Read (delta + 1) bytes as a signed number. + slen1=lambda dvi, delta: dvi._arg(delta + 1, signed=True), + # ulen1: Read (delta + 1) bytes as an unsigned number. + ulen1=lambda dvi, delta: dvi._arg(delta + 1, signed=False), + # olen1: Read (delta + 1) bytes as an unsigned number if less than 4 bytes, + # as a signed number if 4 bytes. + olen1=lambda dvi, delta: dvi._arg(delta + 1, signed=(delta == 3)), +) def _dispatch(table, min, max=None, state=None, args=('raw',)): diff --git a/lib/mpl_toolkits/axisartist/axislines.py b/lib/mpl_toolkits/axisartist/axislines.py index cbcdefe38f7c..ced2703d1ed6 100644 --- a/lib/mpl_toolkits/axisartist/axislines.py +++ b/lib/mpl_toolkits/axisartist/axislines.py @@ -153,12 +153,10 @@ def get_axislabel_pos_angle(self, axes): # TICK def get_tick_transform(self, axes): - return [axes.get_xaxis_transform(), - axes.get_yaxis_transform()][self.nth_coord] + return [axes.get_xaxis_transform(), axes.get_yaxis_transform()][self.nth_coord] class _FloatingAxisArtistHelperBase(_AxisArtistHelperBase): - def __init__(self, nth_coord, value): self.nth_coord = nth_coord self._value = value @@ -168,8 +166,7 @@ def get_nth_coord(self): return self.nth_coord def get_line(self, axes): - raise RuntimeError( - "get_line method should be defined by the derived class") + raise RuntimeError("get_line method should be defined by the derived class") class FixedAxisArtistHelperRectilinear(_FixedAxisArtistHelperBase): @@ -187,10 +184,7 @@ def __init__(self, axes, loc, nth_coord=None): def get_tick_iterators(self, axes): """tick_loc, tick_angle, tick_label""" - if self._loc in ["bottom", "top"]: - angle_normal, angle_tangent = 90, 0 - else: # "left", "right" - angle_normal, angle_tangent = 0, 90 + angle_normal, angle_tangent = {0: (90, 0), 1: (0, 90)}[self.nth_coord] major = self.axis.major major_locs = major.locator() @@ -207,8 +201,7 @@ def _f(locs, labels): c = self._to_xy(loc, const=self._pos) # check if the tick point is inside axes c2 = tick_to_axes.transform(c) - if mpl.transforms._interval_contains_close( - (0, 1), c2[self.nth_coord]): + if mpl.transforms._interval_contains_close((0, 1), c2[self.nth_coord]): yield c, angle_normal, angle_tangent, label return _f(major_locs, major_labels), _f(minor_locs, minor_labels) @@ -245,20 +238,14 @@ def get_axislabel_pos_angle(self, axes): data_to_axes = axes.transData - axes.transAxes p = data_to_axes.transform([self._value, self._value]) verts = self._to_xy(0.5, const=p[fixed_coord]) - if 0 <= verts[fixed_coord] <= 1: - return verts, angle - else: - return None, None + return (verts, angle) if 0 <= verts[fixed_coord] <= 1 else (None, None) def get_tick_transform(self, axes): return axes.transData def get_tick_iterators(self, axes): """tick_loc, tick_angle, tick_label""" - if self.nth_coord == 0: - angle_normal, angle_tangent = 90, 0 - else: - angle_normal, angle_tangent = 0, 90 + angle_normal, angle_tangent = {0: (90, 0), 1: (0, 90)}[self.nth_coord] major = self.axis.major major_locs = major.locator() @@ -326,27 +313,18 @@ def __init__(self, axes): @_api.delete_parameter( "3.9", "nth_coord", addendum="'nth_coord' is now inferred from 'loc'.") - def new_fixed_axis(self, loc, - nth_coord=None, - axis_direction=None, - offset=None, - axes=None, - ): + def new_fixed_axis( + self, loc, nth_coord=None, axis_direction=None, offset=None, axes=None): if axes is None: _api.warn_external( "'new_fixed_axis' explicitly requires the axes keyword.") axes = self.axes if axis_direction is None: axis_direction = loc - helper = FixedAxisArtistHelperRectilinear(axes, loc) - axisline = AxisArtist(axes, helper, offset=offset, - axis_direction=axis_direction) - return axisline + return AxisArtist(axes, FixedAxisArtistHelperRectilinear(axes, loc), + offset=offset, axis_direction=axis_direction) - def new_floating_axis(self, nth_coord, value, - axis_direction="bottom", - axes=None, - ): + def new_floating_axis(self, nth_coord, value, axis_direction="bottom", axes=None): if axes is None: _api.warn_external( "'new_floating_axis' explicitly requires the axes keyword.") @@ -404,8 +382,7 @@ def __call__(self, *args, **kwargs): def __init__(self, *args, grid_helper=None, **kwargs): self._axisline_on = True - self._grid_helper = (grid_helper if grid_helper - else GridHelperRectlinear(self)) + self._grid_helper = grid_helper if grid_helper else GridHelperRectlinear(self) super().__init__(*args, **kwargs) self.toggle_axisline(True) diff --git a/lib/mpl_toolkits/axisartist/floating_axes.py b/lib/mpl_toolkits/axisartist/floating_axes.py index 306ae2c5139a..24c9ce61afa7 100644 --- a/lib/mpl_toolkits/axisartist/floating_axes.py +++ b/lib/mpl_toolkits/axisartist/floating_axes.py @@ -158,11 +158,8 @@ def get_data_boundary(self, side): bottom=(lat1, 1), top=(lat2, 1))[side] - def new_fixed_axis(self, loc, - nth_coord=None, - axis_direction=None, - offset=None, - axes=None): + def new_fixed_axis( + self, loc, nth_coord=None, axis_direction=None, offset=None, axes=None): if axes is None: axes = self.axes if axis_direction is None: @@ -179,23 +176,16 @@ def new_fixed_axis(self, loc, # new_floating_axis will inherit the grid_helper's extremes. - # def new_floating_axis(self, nth_coord, - # value, - # axes=None, - # axis_direction="bottom" - # ): - + # def new_floating_axis(self, nth_coord, value, axes=None, axis_direction="bottom"): # axis = super(GridHelperCurveLinear, # self).new_floating_axis(nth_coord, # value, axes=axes, # axis_direction=axis_direction) - # # set extreme values of the axis helper # if nth_coord == 1: # axis.get_helper().set_extremes(*self._extremes[:2]) # elif nth_coord == 0: # axis.get_helper().set_extremes(*self._extremes[2:]) - # return axis def _update_grid(self, x1, y1, x2, y2): @@ -291,8 +281,6 @@ def adjust_axes_lim(self): self.set_ylim(bbox.ymin, bbox.ymax) -floatingaxes_class_factory = cbook._make_class_factory( - FloatingAxesBase, "Floating{}") -FloatingAxes = floatingaxes_class_factory( - host_axes_class_factory(axislines.Axes)) +floatingaxes_class_factory = cbook._make_class_factory(FloatingAxesBase, "Floating{}") +FloatingAxes = floatingaxes_class_factory(host_axes_class_factory(axislines.Axes)) FloatingSubplot = FloatingAxes diff --git a/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py b/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py index d34a848780e3..08031122c03b 100644 --- a/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py +++ b/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py @@ -272,11 +272,8 @@ def update_grid_finder(self, aux_trans=None, **kwargs): self._old_limits = None # Force revalidation. @_api.make_keyword_only("3.9", "nth_coord") - def new_fixed_axis(self, loc, - nth_coord=None, - axis_direction=None, - offset=None, - axes=None): + def new_fixed_axis( + self, loc, nth_coord=None, axis_direction=None, offset=None, axes=None): if axes is None: axes = self.axes if axis_direction is None: @@ -287,11 +284,7 @@ def new_fixed_axis(self, loc, # the floating_axig.GridHelperCurveLinear subclass? return axisline - def new_floating_axis(self, nth_coord, - value, - axes=None, - axis_direction="bottom" - ): + def new_floating_axis(self, nth_coord, value, axes=None, axis_direction="bottom"): if axes is None: axes = self.axes helper = FloatingAxisArtistHelper( @@ -317,22 +310,15 @@ def get_gridlines(self, which="major", axis="both"): return grid_lines def get_tick_iterator(self, nth_coord, axis_side, minor=False): - - # axisnr = dict(left=0, bottom=1, right=2, top=3)[axis_side] angle_tangent = dict(left=90, right=90, bottom=0, top=0)[axis_side] - # angle = [0, 90, 180, 270][axisnr] lon_or_lat = ["lon", "lat"][nth_coord] if not minor: # major ticks - for (xy, a), l in zip( + for (xy, angle_normal), l in zip( self._grid_info[lon_or_lat]["tick_locs"][axis_side], self._grid_info[lon_or_lat]["tick_labels"][axis_side]): - angle_normal = a yield xy, angle_normal, angle_tangent, l else: - for (xy, a), l in zip( + for (xy, angle_normal), l in zip( self._grid_info[lon_or_lat]["tick_locs"][axis_side], self._grid_info[lon_or_lat]["tick_labels"][axis_side]): - angle_normal = a yield xy, angle_normal, angle_tangent, "" - # for xy, a, l in self._grid_info[lon_or_lat]["ticks"][axis_side]: - # yield xy, a, ""