yaxis_text_base + \ Affine2D().translate(-8.0, 0.0) self._yaxis_text2_transform = \ yaxis_text_base + \ Affine2D().translate(8.0, 0.0) def _get_affine_transform(self): transform = self._get_core_transform(1) xscale, _ = transform.transform_point((0, 0)) _, yscale = transform.transform_point((0, np.pi / 2.0)) return Affine2D() \ .scale(0.5 / xscale, 0.5 / yscale) \ .translate(0.5, 0.5) projection_registry.register(AstroDegreesMollweideAxes) class AstroHoursMollweideAxes(AstroDegreesMollweideAxes): """Mollweide axes with phi axis flipped and in hours from 24 to 0 instead of in degrees from -180 to 180.""" name = 'astro hours mollweide' class RaFormatter(Formatter): # Copied from matplotlib.geo.GeoAxes.ThetaFormatter and modified def __init__(self, round_to=1.0): self._round_to = round_to def __call__(self, x, pos=None): hours = (x / np.pi) * 12.
yaxis_text_base + \ Affine2D().translate(-8.0, 0.0) self._yaxis_text2_transform = \ yaxis_text_base + \ Affine2D().translate(8.0, 0.0) def _get_affine_transform(self): transform = self._get_core_transform(1) xscale, _ = transform.transform_point((0, 0)) _, yscale = transform.transform_point((0, np.pi / 2.0)) return Affine2D() \ .scale(0.5 / xscale, 0.5 / yscale) \ .translate(0.5, 0.5) projection_registry.register(AstroMollweideAxes) def wrapped_angle(a): """Convert an angle to a reference angle between 0 and 2*pi.""" return np.mod(a, 2 * np.pi) def reference_angle(a): """Convert an angle to a reference angle between -pi and pi.""" a = np.mod(a, 2 * np.pi) return np.where(a <= np.pi, a, a - 2 * np.pi) def reference_angle_deg(a): """Convert an angle to a reference angle between -180 and 180 degrees."""
label = 'target {0:g}{1:s}\nconfidence band'.format( 100 * alpha, percent_sign) self.annotate( label, xy=(1, 1), xytext=(0, 0), xycoords='axes fraction', textcoords='offset points', annotation_clip=False, horizontalalignment='right', verticalalignment='bottom', fontsize=fontsize, arrowprops=dict( arrowstyle="->", shrinkA=0, shrinkB=2, linewidth=0.5, connectionstyle="angle,angleA=0,angleB=45,rad=0")) return self.fill_betweenx(p, ci_lo, ci_hi, **kwargs) @classmethod def _as_mpl_axes(cls): """Support placement in figure using the `projection` keyword argument. See http://matplotlib.org/devel/add_new_projection.html""" return cls, {} projection_registry.register(PPPlot)
moddict = globals() # # Create subclasses and register all projections: # '{astro|geo} {hours|degrees} {aitoff|globe|mollweide|zoom}' # bases1 = (Astro, Geo) bases2 = (Hours, Degrees) bases3 = (Aitoff, Globe, Mollweide, Zoom) for bases in product(bases1, bases2, bases3): class_name = "".join(cls.__name__ for cls in bases) + "Axes" projection = " ".join(cls.__name__.lower() for cls in bases) new_class = type(class_name, bases, {"name": projection}) projection_registry.register(new_class) moddict[class_name] = new_class __all__.append(class_name) # # Create some synonyms: # 'astro' will be short for 'astro hours', # 'geo' will be short for 'geo degrees' # for base1, base2 in zip(bases1, bases2): for base3 in (Aitoff, Globe, Mollweide, Zoom): bases = (base1, base2, base3) orig_class_name = "".join(cls.__name__ for cls in bases) + "Axes" orig_class = moddict[orig_class_name] class_name = "".join(cls.__name__ for cls in (base1, base3)) + "Axes" projection = " ".join(cls.__name__.lower() for cls in (base1, base3))
if annotate: percent_sign = r'\%' if matplotlib.rcParams['text.usetex'] else '%' label = 'target {0:g}{1:s}\nconfidence band'.format( 100 * alpha, percent_sign) self.annotate( label, xy=(1, 1), xytext=(0, 0), xycoords='axes fraction', textcoords='offset points', annotation_clip=False, horizontalalignment='right', verticalalignment='bottom', fontsize=fontsize, arrowprops=dict( arrowstyle="->", shrinkA=0, shrinkB=2, linewidth=0.5, connectionstyle="angle,angleA=0,angleB=45,rad=0") ) return self.fill_betweenx(p, ci_lo, ci_hi, **kwargs) @classmethod def _as_mpl_axes(cls): """Support placement in figure using the `projection` keyword argument. See http://matplotlib.org/devel/add_new_projection.html""" return cls, {} projection_registry.register(PPPlot)
class GeoHoursAitoffAllSkyAxes(Geo, Hours, Aitoff, AllSkyAxes): name = 'geo hours aitoff' class GeoDegreesMollweideAllSkyAxes(Geo, Degrees, Mollweide, AllSkyAxes): name = 'geo degrees mollweide' class GeoHoursMollweideAllSkyAxes(Geo, Hours, Mollweide, AllSkyAxes): name = 'geo hours mollweide' projection_registry.register( AstroDegreesAitoffAllSkyAxes, AstroDegreesMollweideAllSkyAxes, AstroHoursAitoffAllSkyAxes, AstroHoursMollweideAllSkyAxes, GeoDegreesAitoffAllSkyAxes, GeoHoursAitoffAllSkyAxes, GeoDegreesMollweideAllSkyAxes, GeoHoursMollweideAllSkyAxes, GlobeAxes, ZoomSkyAxes) class ScaleBar(FancyArrowPatch): def _func(self, dx, x, y): p1, p2 = self._transAxesToWorld.transform([[x, y], [x + dx, y]]) p1 = SkyCoord(*p1, unit=u.deg) p2 = SkyCoord(*p2, unit=u.deg) return np.square((p1.separation(p2) - self._length).value) def __init__(self, ax, xy, length, *args, **kwargs): x, y = xy self._ax = ax self._length = length
sqrt2 = np.sqrt(2) sintheta = y / sqrt2 with np.errstate(invalid='ignore'): costheta = np.sqrt(1. - 0.5 * y * y) longitude = 0.25 * sqrt2 * np.pi * x / costheta latitude = np.arcsin(2 / np.pi * (np.arcsin(sintheta) + sintheta * costheta)) return np.concatenate((longitude, latitude), 1) transform.__doc__ = Transform.transform.__doc__ transform_non_affine = transform def _get_core_transform(self, resolution): return self.FixedMollweideTransform(resolution) projection_registry.register(FixedMollweideAxes) else: class FixedMollweideAxes(MollweideAxes): """Patched version of matplotlib's Mollweide projection that implements a correct inverse transform.""" class FixedMollweideTransform(MollweideAxes.MollweideTransform): def inverted(self): return FixedMollweideAxes.InvertedFixedMollweideTransform(self._resolution) inverted.__doc__ = Transform.inverted.__doc__ class InvertedFixedMollweideTransform(MollweideAxes.InvertedMollweideTransform): def inverted(self): return FixedMollweideAxes.FixedMollweideTransform(self._resolution)
from matplotlib.axes import Axes from matplotlib.figure import Figure from mpl_toolkits.mplot3d import Axes3D from matplotlib.projections import projection_registry from retina.core import axes, layer, calc_context # Registers the Fovea2D and Fovea3D classes as valid projections. projection_registry.register(axes.Fovea2D) projection_registry.register(axes.Fovea3D)