""" The base polar transform. This handles projection *theta* and *r* into Cartesian coordinate space *x* and *y*, but does not perform the ultimate affine transformation into the correct position. """
_apply_theta_transforms=True):
def __str__(self): return ("{}(\n" "{},\n" " use_rmin={},\n" " _apply_theta_transforms={})" .format(type(self).__name__, mtransforms._indent_str(self._axis), self._use_rmin, self._apply_theta_transforms))
# PolarAxes does not use the theta transforms here, but apply them for # backwards-compatibility if not being used by it. t *= self._axis.get_theta_direction() t += self._axis.get_theta_offset()
mtransforms.Transform.transform_non_affine.__doc__
mtransforms.Transform.transform_path_non_affine.__doc__
self._apply_theta_transforms)
""" The affine part of the polar projection. Scales the output so that maximum radius rests on the edge of the axes circle. """ """ *limits* is the view limit of the data. The only part of its bounds that is used is the y limits (for the radius limits). The theta range is handled by the non-affine transform. """
def __str__(self): return ("{}(\n" "{},\n" "{})" .format(type(self).__name__, mtransforms._indent_str(self._scale_transform), mtransforms._indent_str(self._limits)))
.scale(0.5 / yscale) \ .translate(0.5, 0.5)
""" The inverse of the polar transform, mapping Cartesian coordinate space *x* and *y* back to *theta* and *r*. """
_apply_theta_transforms=True):
def __str__(self): return ("{}(\n" "{},\n" " use_rmin={},\n" " _apply_theta_transforms={})" .format(type(self).__name__, mtransforms._indent_str(self._axis), self._use_rmin, self._apply_theta_transforms))
# At x=y=r=0 this will raise an # invalid value warning when doing 0/0 # Divide by zero warnings are only raised when # the numerator is different from 0. That # should not happen here.
# PolarAxes does not use the theta transforms here, but apply them for # backwards-compatibility if not being used by it. theta -= self._axis.get_theta_offset() theta *= self._axis.get_theta_direction() theta %= 2 * np.pi
mtransforms.Transform.transform_non_affine.__doc__
return PolarAxes.PolarTransform(self._axis, self._use_rmin, self._apply_theta_transforms)
""" Used to format the *theta* tick labels. Converts the native unit of radians into degrees and adds a degree symbol. """
format_str = r"${value:0.{digits:d}f}^\circ$" return format_str.format(value=np.rad2deg(x), digits=digits) else: # we use unicode, rather than mathtext with \circ, so # that it will work correctly with any arbitrary font # (assuming it has a degree sign), whereas $5\circ$ # will only work correctly with one of the supported # math fonts (Computer Modern and STIX)
self._axis.set_view_interval(*np.deg2rad((vmin, vmax)))
return np.rad2deg(self._axis.get_minpos())
return np.rad2deg(self._axis.get_data_interval())
self._axis.set_data_interval(*np.deg2rad((vmin, vmax)))
return self._axis.get_tick_space()
""" Used to locate theta ticks.
This will work the same as the base locator except in the case that the view spans the entire circle. In such cases, the previously used default locations of every 45 degrees are returned. """
else: return np.deg2rad(self.base())
return self.base.autoscale()
return self.base.pan(numsteps)
return self.base.refresh()
vmin, vmax = np.rad2deg((vmin, vmax)) return np.deg2rad(self.base.view_limits(vmin, vmax))
return self.base.zoom(direction)
""" A theta-axis tick.
This subclass of `XTick` provides angular ticks with some small modification to their re-positioning such that ticks are rotated based on tick location. This results in ticks that are correctly perpendicular to the arc spine.
When 'auto' rotation is enabled, labels are also rotated to be parallel to the spine. The label padding is also applied here since it's not possible to use a generic axes transform to produce tick-specific padding. """ 0, 0, axes.figure.dpi_scale_trans) 0, 0, axes.figure.dpi_scale_trans)
# Ensure transform is correct; sometimes this gets reset. self.label1.set_transform(trans + self._text1_translate) self.label2.set_transform(trans + self._text2_translate)
trans = mtransforms.Affine2D().scale(1.0, 1.0).rotate(angle) else: # Don't modify custom tick line markers. trans = self.tick1line._marker._transform marker = self.tick2line.get_marker() if marker in (mmarkers.TICKUP, '|'): trans = mtransforms.Affine2D().scale(1.0, 1.0).rotate(angle) elif marker == mmarkers.TICKDOWN: trans = mtransforms.Affine2D().scale(1.0, -1.0).rotate(angle) else: # Don't modify custom tick line markers. trans = self.tick2line._marker._transform self.tick2line._marker._transform = trans
else: if text_angle > 90: text_angle -= 180 elif text_angle < -90: text_angle += 180 text_angle += user_angle self.label2.set_rotation(text_angle)
# This extra padding helps preserve the look from previous releases but # is also needed because labels are anchored to their center. self._loc * axes.get_theta_direction() + axes.get_theta_offset())
""" A theta Axis.
This overrides certain properties of an `XAxis` to provide special-casing for an angular axis. """
else:
'Copy the props from src tick to dest tick' return
# Ensure that tick transforms are independent so that padding works.
""" Used to locate radius ticks.
Ensures that all ticks are strictly positive. For all other tasks, it delegates to the base :class:`~matplotlib.ticker.Locator` (which may be different depending on the scale of the *r*-axis. """
show_all = True # Ensure previous behaviour with full circle non-annular views. if self._axes: if _is_full_circle_rad(*self._axes.viewLim.intervalx): rorigin = self._axes.get_rorigin() if self._axes.get_rmin() <= rorigin: show_all = False
if show_all: return self.base() else: return [tick for tick in self.base() if tick > rorigin]
return self.base.autoscale()
return self.base.pan(numsteps)
return self.base.zoom(direction)
return self.base.refresh()
""" Apply a padding shift based on axes theta limits.
This is used to create padding for radial ticks.
Parameters ---------- axes : matplotlib.axes.Axes The owning axes; used to determine limits. pad : float The padding to apply, in points. start : str, {'min', 'max', 'rlabel'} Whether to shift away from the start (``'min'``) or the end (``'max'``) of the axes, or using the rlabel position (``'rlabel'``). """ axes.figure.dpi_scale_trans)
def __str__(self): return ("{}(\n" "{},\n" "{},\n" "{})" .format(type(self).__name__, mtransforms._indent_str(self.axes), mtransforms._indent_str(self.pad), mtransforms._indent_str(repr(self.mode))))
if self._invalid: if self.mode == 'rlabel': angle = ( np.deg2rad(self.axes.get_rlabel_position()) * self.axes.get_theta_direction() + self.axes.get_theta_offset() ) else: if self.mode == 'min': angle = self.axes._realViewLim.xmin elif self.mode == 'max': angle = self.axes._realViewLim.xmax
if self.mode in ('rlabel', 'min'): padx = np.cos(angle - np.pi / 2) pady = np.sin(angle - np.pi / 2) else: padx = np.cos(angle + np.pi / 2) pady = np.sin(angle + np.pi / 2)
self._t = (self.pad * padx / 72, self.pad * pady / 72) return mtransforms.ScaledTranslation.get_matrix(self)
""" A radial-axis tick.
This subclass of `YTick` provides radial ticks with some small modification to their re-positioning such that ticks are rotated based on axes limits. This results in ticks that are correctly perpendicular to the spine. Labels are also rotated to be perpendicular to the spine, when 'auto' rotation is enabled. """
# Note: angle is the (spine angle - 90) because it's used for the tick # & text setup, so all numbers below are -90 from (normed) spine angle. if start: if -90 <= angle <= 90: return 'left', 'center' else: return 'right', 'center' else: if -90 <= angle <= 90: return 'right', 'center' else: return 'left', 'center' else: elif angle < -23.5: return 'left', 'top' elif angle < 22.5: return 'left', 'center' elif angle < 67.5: return 'left', 'bottom' elif angle < 112.5: return 'center', 'bottom' elif angle < 157.5: return 'right', 'bottom' elif angle < 202.5: return 'right', 'center' elif angle < 247.5: return 'right', 'top' else: return 'center', 'top' else: if angle < -68.5: return 'center', 'bottom' elif angle < -23.5: return 'right', 'bottom' elif angle < 22.5: return 'right', 'center' elif angle < 67.5: return 'right', 'top' elif angle < 112.5: return 'center', 'top' elif angle < 157.5: return 'left', 'top' elif angle < 202.5: return 'left', 'center' elif angle < 247.5: return 'left', 'bottom' else: return 'center', 'bottom'
offset) % 360 - 90 text_angle = angle - 180 text_angle = angle + 180 else: else: else: tick_angle = np.deg2rad(angle + 180) text_angle = angle - 180 text_angle = angle + 180 else: text_angle += user_angle else: else: .scale(1.0, 1.0) .rotate(tick_angle)) elif marker == '_': trans = (mtransforms.Affine2D() .scale(1.0, 1.0) .rotate(tick_angle + np.pi / 2)) elif marker == mmarkers.TICKRIGHT: trans = (mtransforms.Affine2D() .scale(-1.0, 1.0) .rotate(tick_angle)) else: # Don't modify custom tick line markers. trans = self.tick1line._marker._transform
else: else: tick_angle = np.deg2rad(angle + 180) text_angle = angle - 180 text_angle = angle + 180 else: text_angle += user_angle else: ha, va = self._determine_anchor(mode, angle, direction < 0) self.label2.set_ha(ha) self.label2.set_va(va) self.label2.set_rotation(text_angle) marker = self.tick2line.get_marker() if marker == mmarkers.TICKLEFT: trans = (mtransforms.Affine2D() .scale(1.0, 1.0) .rotate(tick_angle)) elif marker == '_': trans = (mtransforms.Affine2D() .scale(1.0, 1.0) .rotate(tick_angle + np.pi / 2)) elif marker == mmarkers.TICKRIGHT: trans = (mtransforms.Affine2D() .scale(-1.0, 1.0) .rotate(tick_angle)) else: # Don't modify custom tick line markers. trans = self.tick2line._marker._transform self.tick2line._marker._transform = trans
""" A radial Axis.
This overrides certain properties of a `YAxis` to provide special-casing for a radial axis. """
else:
self.axes))
""" Determine if a wedge (in degrees) spans the full circle.
The condition is derived from :class:`~matplotlib.patches.Wedge`. """
""" Determine if a wedge (in radians) spans the full circle.
The condition is derived from :class:`~matplotlib.patches.Wedge`. """
""" Transform (theta,r) wedge Bbox into axes bounding box.
Parameters ---------- center : (float, float) Center of the wedge viewLim : `~matplotlib.transforms.Bbox` Bbox determining the boundaries of the wedge originLim : `~matplotlib.transforms.Bbox` Bbox determining the origin for the wedge, if different from *viewLim* """ np.array([[0.0, 0.0], [1.0, 1.0]], np.float), **kwargs)
def __str__(self): return ("{}(\n" "{},\n" "{},\n" "{})" .format(type(self).__name__, mtransforms._indent_str(self._center), mtransforms._indent_str(self._viewLim), mtransforms._indent_str(self._originLim)))
# Scale angular limits to work with Wedge. points[:, 0] = points[::-1, 0]
# Scale radial limits based on origin radius.
# Scale radial limits to match axes limits.
# Generate bounding box for wedge. points[0, 0], points[1, 0], width=width)
# Ensure equal aspect ratio. deltah = (w - h) / 2.0 deltaw = 0.0 deltah = 0.0 deltaw = (h - w) / 2.0 else:
""" A polar graph projection, where the input dimensions are *theta*, *r*.
Theta starts pointing east and goes anti-clockwise. """
theta_offset=0, theta_direction=1, rlabel_position=22.5, **kwargs): """ Create a new Polar Axes for a polar plot. """
"move this out of __init__ because non-separable axes don't use it" # Calling polar_axes.xaxis.cla() or polar_axes.xaxis.cla() # results in weird artifacts. Therefore we disable this for # now. # self.spines['polar'].register_axis(self.yaxis)
# A view limit where the minimum radius can be locked if the user # specifies an alternate origin.
# Handle angular offset and direction. .scale(self._default_theta_direction, 1.0) .translate(self._default_theta_offset, 0.0) self._direction, self._theta_offset) # A view limit shifted to the correct location after accounting for # orientation and offset. self.transShift)
# Transforms the x and y axis separately by a scale factor # It is assumed that this part will have non-linear components mtransforms.IdentityTransform())
# Scale view limit into a bbox around the selected wedge. This may be # smaller than the usual unit axes rectangle if not plotting the full # circle. self._realViewLim, self._originViewLim)
# Scale the wedge to fill the axes.
# Scale the axes to fill the figure.
# A (possibly non-linear) projection on the (already scaled) # data. This one is aware of rmin self, _apply_theta_transforms=False) # Add dependency on rorigin.
# An affine transformation on the data, generally to limit the # range of the axes self._originViewLim)
# The complete data transformation stack -- from data all the # way to display coordinates self.transScale + self.transShift + self.transProjection + (self.transProjectionAffine + self.transWedge + self.transAxes))
# This is the transform for theta-axis ticks. It is # equivalent to transData, except it always puts r == 0.0 and r == 1.0 # at the edge of the axis circles. mtransforms.blended_transform_factory( mtransforms.IdentityTransform(), mtransforms.BboxTransformTo(self.viewLim)) + self.transData) # The theta labels are flipped along the radius, so that text 1 is on # the outside by default. This should work the same as before. .translate(0.0, -0.5) \ .scale(1.0, -1.0) \ .translate(0.0, 0.5)
# This is the transform for r-axis ticks. It scales the theta # axis so the gridlines from 0.0 to 1.0, now go from thetamin to # thetamax. mtransforms.blended_transform_factory( mtransforms.BboxTransformTo(self.viewLim), mtransforms.IdentityTransform()) + self.transData) # The r-axis labels are put at an angle and padded in the r-direction .translate(self._default_rlabel_position, 0.0) self._r_label_position + self.transData)
raise ValueError( "'which' must be one of 'tick1', 'tick2', or 'grid'")
else: raise ValueError( "'which' must be one of 'tick1', 'tick2', or 'grid'")
else: halign = 'right' pad_shift = _ThetaShift(self, pad, 'max')
else:
thetamin, thetamax = thetamax, thetamin
# Backwards-compatibility: Any subclassed Axes might override the # patch to not be the Wedge that PolarAxes uses.
# For backwards compatibility, any subclassed Axes might override the # spines to not include start/end that PolarAxes uses. yaxis_text_transform = self._yaxis_transform else: self._yaxis_text_transform.set(yaxis_text_transform) self.yaxis.reset_ticks() self.yaxis.set_clip_path(self.patch)
('polar', mspines.Spine.arc_spine(self, 'top', (0.5, 0.5), 0.5, 0.0, 360.0)), ('start', mspines.Spine.linear_spine(self, 'left')), ('end', mspines.Spine.linear_spine(self, 'right')), ('inner', mspines.Spine.arc_spine(self, 'bottom', (0.5, 0.5), 0.0, 0.0, 360.0)) ])
self.viewLim.x1 = np.deg2rad(thetamax)
self.viewLim.x0 = np.deg2rad(thetamin)
if 'thetamin' in kwargs: kwargs['xmin'] = np.deg2rad(kwargs.pop('thetamin')) if 'thetamax' in kwargs: kwargs['xmax'] = np.deg2rad(kwargs.pop('thetamax')) return tuple(np.rad2deg(self.set_xlim(*args, **kwargs)))
""" Set the offset for the location of 0 in radians. """
""" Get the offset for the location of 0 in radians. """
""" Sets the location of theta's zero. (Calls set_theta_offset with the correct value in radians under the hood.)
loc : str May be one of "N", "NW", "W", "SW", "S", "SE", "E", or "NE".
offset : float, optional An offset in degrees to apply from the specified `loc`. **Note:** this offset is *always* applied counter-clockwise regardless of the direction setting. """ 'N': np.pi * 0.5, 'NW': np.pi * 0.75, 'W': np.pi, 'SW': np.pi * 1.25, 'S': np.pi * 1.5, 'SE': np.pi * 1.75, 'E': 0, 'NE': np.pi * 0.25}
""" Set the direction in which theta increases.
clockwise, -1: Theta increases in the clockwise direction
counterclockwise, anticlockwise, 1: Theta increases in the counterclockwise direction """ mtx[0, 0] = -1 mtx[0, 0] = 1 else: raise ValueError( "direction must be 1, -1, clockwise or counterclockwise")
""" Get the direction in which theta increases.
-1: Theta increases in the clockwise direction
1: Theta increases in the counterclockwise direction """
self.viewLim.y1 = rmax
return self.viewLim.ymax
self.viewLim.y0 = rmin
return self.viewLim.ymin
if 'rmin' in kwargs: kwargs['ymin'] = kwargs.pop('rmin') if 'rmax' in kwargs: kwargs['ymax'] = kwargs.pop('rmax') return self.set_ylim(*args, **kwargs)
""" Returns ------- float The theta position of the radius labels in degrees. """
"""Updates the theta position of the radius labels.
Parameters ---------- value : number The angular position of the radius labels in degrees. """ self._r_label_position.clear().translate(np.deg2rad(value), 0.0)
Axes.set_yscale(self, *args, **kwargs) self.yaxis.set_major_locator( self.RadialLocator(self.yaxis.get_major_locator(), self))
return Axes.set_yscale(self, *args, **kwargs)
return Axes.set_yticks(self, *args, **kwargs)
""" Set the theta gridlines in a polar plot.
Parameters ---------- angles : tuple with floats, degrees The angles of the theta gridlines.
labels : tuple with strings or None The labels to use at each theta gridline. The `.projections.polar.ThetaFormatter` will be used if None.
fmt : str or None Format string used in `matplotlib.ticker.FormatStrFormatter`. For example '%f'. Note that the angle that is used is in radians.
Returns ------- lines, labels : list of `.lines.Line2D`, list of `.text.Text` *lines* are the theta gridlines and *labels* are the tick labels.
Other Parameters ---------------- **kwargs *kwargs* are optional `~.Text` properties for the labels.
See Also -------- .PolarAxes.set_rgrids .Axis.get_gridlines .Axis.get_ticklabels """
# Make sure we take into account unitized data angles = self.convert_yunits(angles) angles = np.deg2rad(angles) self.set_xticks(angles) if labels is not None: self.set_xticklabels(labels) elif fmt is not None: self.xaxis.set_major_formatter(mticker.FormatStrFormatter(fmt)) for t in self.xaxis.get_ticklabels(): t.update(kwargs) return self.xaxis.get_ticklines(), self.xaxis.get_ticklabels()
**kwargs): """ Set the radial gridlines on a polar plot.
Parameters ---------- radii : tuple with floats The radii for the radial gridlines
labels : tuple with strings or None The labels to use at each radial gridline. The `matplotlib.ticker.ScalarFormatter` will be used if None.
angle : float The angular position of the radius labels in degrees.
fmt : str or None Format string used in `matplotlib.ticker.FormatStrFormatter`. For example '%f'.
Returns ------- lines, labels : list of `.lines.Line2D`, list of `.text.Text` *lines* are the radial gridlines and *labels* are the tick labels.
Other Parameters ---------------- **kwargs *kwargs* are optional `~.Text` properties for the labels.
See Also -------- .PolarAxes.set_thetagrids .Axis.get_gridlines .Axis.get_ticklabels """ # Make sure we take into account unitized data radii = self.convert_xunits(radii) radii = np.asarray(radii)
self.set_yticks(radii) if labels is not None: self.set_yticklabels(labels) elif fmt is not None: self.yaxis.set_major_formatter(mticker.FormatStrFormatter(fmt)) if angle is None: angle = self.get_rlabel_position() self.set_rlabel_position(angle) for t in self.yaxis.get_ticklabels(): t.update(kwargs) return self.yaxis.get_gridlines(), self.yaxis.get_ticklabels()
if scale != 'linear': raise NotImplementedError( "You can not set the xscale on a polar plot.")
""" Return a format string formatting the coordinate using Unicode characters. """ if theta < 0: theta += 2 * np.pi theta /= np.pi return ('\N{GREEK SMALL LETTER THETA}=%0.3f\N{GREEK SMALL LETTER PI} ' '(%0.3f\N{DEGREE SIGN}), r=%0.3f') % (theta, theta * 180.0, r)
''' Return the aspect ratio of the data itself. For a polar plot, this should always be 1.0 '''
# # # Interactive panning
""" Return *True* if this axes supports the zoom box button functionality.
Polar axes do not support zoom boxes. """ return False
""" Return *True* if this axes supports the pan/zoom button functionality.
For polar axes, this is slightly misleading. Both panning and zooming are performed by the same button. Panning is performed in azimuth while zooming is done along the radial. """ return True
angle = np.deg2rad(self.get_rlabel_position()) mode = '' if button == 1: epsilon = np.pi / 45.0 t, r = self.transData.inverted().transform_point((x, y)) if angle - epsilon <= t <= angle + epsilon: mode = 'drag_r_labels' elif button == 3: mode = 'zoom'
self._pan_start = types.SimpleNamespace( rmax=self.get_rmax(), trans=self.transData.frozen(), trans_inverse=self.transData.inverted().frozen(), r_label_angle=self.get_rlabel_position(), x=x, y=y, mode=mode)
del self._pan_start
p = self._pan_start
if p.mode == 'drag_r_labels': startt, startr = p.trans_inverse.transform_point((p.x, p.y)) t, r = p.trans_inverse.transform_point((x, y))
# Deal with theta dt0 = t - startt dt1 = startt - t if abs(dt1) < abs(dt0): dt = abs(dt1) * np.sign(dt0) * -1.0 else: dt = dt0 * -1.0 dt = (dt / np.pi) * 180.0 self.set_rlabel_position(p.r_label_angle - dt)
trans, vert1, horiz1 = self.get_yaxis_text1_transform(0.0) trans, vert2, horiz2 = self.get_yaxis_text2_transform(0.0) for t in self.yaxis.majorTicks + self.yaxis.minorTicks: t.label1.set_va(vert1) t.label1.set_ha(horiz1) t.label2.set_va(vert2) t.label2.set_ha(horiz2)
elif p.mode == 'zoom': startt, startr = p.trans_inverse.transform_point((p.x, p.y)) t, r = p.trans_inverse.transform_point((x, y))
# Deal with r scale = r / startr self.set_rmax(p.rmax / scale)
# to keep things all self contained, we can put aliases to the Polar classes # defined above. This isn't strictly necessary, but it makes some of the # code more readable (and provides a backwards compatible Polar API)
# These are a couple of aborted attempts to project a polar plot using # cubic bezier curves.
# def transform_path(self, path): # twopi = 2.0 * np.pi # halfpi = 0.5 * np.pi
# vertices = path.vertices # t0 = vertices[0:-1, 0] # t1 = vertices[1: , 0] # td = np.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) # maxtd = td.max() # interpolate = np.ceil(maxtd / halfpi) # if interpolate > 1.0: # vertices = self.interpolate(vertices, interpolate)
# vertices = self.transform(vertices)
# result = np.zeros((len(vertices) * 3 - 2, 2), float) # codes = mpath.Path.CURVE4 * np.ones((len(vertices) * 3 - 2, ), # mpath.Path.code_type) # result[0] = vertices[0] # codes[0] = mpath.Path.MOVETO
# kappa = 4.0 * ((np.sqrt(2.0) - 1.0) / 3.0) # kappa = 0.5
# p0 = vertices[0:-1] # p1 = vertices[1: ]
# x0 = p0[:, 0:1] # y0 = p0[:, 1: ] # b0 = ((y0 - x0) - y0) / ((x0 + y0) - x0) # a0 = y0 - b0*x0
# x1 = p1[:, 0:1] # y1 = p1[:, 1: ] # b1 = ((y1 - x1) - y1) / ((x1 + y1) - x1) # a1 = y1 - b1*x1
# x = -(a0-a1) / (b0-b1) # y = a0 + b0*x
# xk = (x - x0) * kappa + x0 # yk = (y - y0) * kappa + y0
# result[1::3, 0:1] = xk # result[1::3, 1: ] = yk
# xk = (x - x1) * kappa + x1 # yk = (y - y1) * kappa + y1
# result[2::3, 0:1] = xk # result[2::3, 1: ] = yk
# result[3::3] = p1
# print(vertices[-2:]) # print(result[-2:])
# return mpath.Path(result, codes)
# twopi = 2.0 * np.pi # halfpi = 0.5 * np.pi
# vertices = path.vertices # t0 = vertices[0:-1, 0] # t1 = vertices[1: , 0] # td = np.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) # maxtd = td.max() # interpolate = np.ceil(maxtd / halfpi)
# print("interpolate", interpolate) # if interpolate > 1.0: # vertices = self.interpolate(vertices, interpolate)
# result = np.zeros((len(vertices) * 3 - 2, 2), float) # codes = mpath.Path.CURVE4 * np.ones((len(vertices) * 3 - 2, ), # mpath.Path.code_type) # result[0] = vertices[0] # codes[0] = mpath.Path.MOVETO
# kappa = 4.0 * ((np.sqrt(2.0) - 1.0) / 3.0) # tkappa = np.arctan(kappa) # hyp_kappa = np.sqrt(kappa*kappa + 1.0)
# t0 = vertices[0:-1, 0] # t1 = vertices[1: , 0] # r0 = vertices[0:-1, 1] # r1 = vertices[1: , 1]
# td = np.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) # td_scaled = td / (np.pi * 0.5) # rd = r1 - r0 # r0kappa = r0 * kappa * td_scaled # r1kappa = r1 * kappa * td_scaled # ravg_kappa = ((r1 + r0) / 2.0) * kappa * td_scaled
# result[1::3, 0] = t0 + (tkappa * td_scaled) # result[1::3, 1] = r0*hyp_kappa # # result[1::3, 1] = r0 / np.cos(tkappa * td_scaled) # # np.sqrt(r0*r0 + ravg_kappa*ravg_kappa)
# result[2::3, 0] = t1 - (tkappa * td_scaled) # result[2::3, 1] = r1*hyp_kappa # # result[2::3, 1] = r1 / np.cos(tkappa * td_scaled) # # np.sqrt(r1*r1 + ravg_kappa*ravg_kappa)
# result[3::3, 0] = t1 # result[3::3, 1] = r1
# print(vertices[:6], result[:6], t0[:6], t1[:6], td[:6], # td_scaled[:6], tkappa) # result = self.transform(result) # return mpath.Path(result, codes) # transform_path_non_affine = transform_path |