def show(self,
             length,
             label=None,
             corner='bottom right',
             frame=False,
             borderpad=0.4,
             pad=0.5,
             **kwargs):
        '''
        Overlay a scale bar on the image.

        Parameters
        ----------

        length : float
            The length of the scalebar

        label : str, optional
            Label to place below the scalebar

        corner : int, optional
            Where to place the scalebar. Acceptable values are:, 'left',
            'right', 'top', 'bottom', 'top left', 'top right', 'bottom
            left' (default), 'bottom right'

        frame : str, optional
            Whether to display a frame behind the scalebar (default is False)

        kwargs
            Additional arguments are passed to the matplotlib Rectangle and
            Text classes. See the matplotlib documentation for more details.
            In cases where the same argument exists for the two objects, the
            argument is passed to both the Text and Rectangle instance.
        '''

        self._length = length
        self._base_settings['corner'] = corner
        self._base_settings['frame'] = frame
        self._base_settings['borderpad'] = borderpad
        self._base_settings['pad'] = pad

        degrees_per_pixel = wcs_util.degperpix(self._wcs)

        length = length / degrees_per_pixel

        try:
            self._scalebar.remove()
        except:
            pass

        if isinstance(corner, basestring):
            corner = corners[corner]

        self._scalebar = AnchoredSizeBar(self._ax.transData, length, label, corner, \
                              pad=pad, borderpad=borderpad, sep=5, frameon=frame)

        self._ax.add_artist(self._scalebar)

        self.set(**kwargs)
Example #2
0
    def drawscale(self, ax, color='white', fontsize=None):
        from mpl_toolkits.axes_grid.anchored_artists import AnchoredSizeBar
        l = (self.cut.size[0]) * 0.2
        l = l // 10**int(log10(l)) * 10**int(log10(l))
        if l > 500:
            l /= 1000.0
            l = int(l + 0.5)
            text = r"%g Mpc/h" % l
            l *= 1000.0
        else:
            text = r"%g Kpc/h" % l

        print text
        b = AnchoredSizeBar(ax.transData,
                            l,
                            text,
                            loc=8,
                            pad=0.1,
                            borderpad=0.5,
                            sep=5,
                            frameon=False)
        for r in b.size_bar.findobj(Rectangle):
            r.set_edgecolor(color)
        for t in b.txt_label.findobj(Text):
            t.set_color(color)
            if fontsize is not None:
                t.set_fontsize(fontsize)

        ax.add_artist(b)
Example #3
0
    def show(self, length, label=None, corner='bottom right', frame=False, borderpad=0.4, pad=0.5, **kwargs):
        '''
        Overlay a scale bar on the image.

        Parameters
        ----------

        length : float, or quantity
            The length of the scalebar in degrees, an angular quantity, or angular unit

        label : str, optional
            Label to place below the scalebar

        corner : int, optional
            Where to place the scalebar. Acceptable values are:, 'left',
            'right', 'top', 'bottom', 'top left', 'top right', 'bottom
            left' (default), 'bottom right'

        frame : str, optional
            Whether to display a frame behind the scalebar (default is False)

        kwargs
            Additional arguments are passed to the matplotlib Rectangle and
            Text classes. See the matplotlib documentation for more details.
            In cases where the same argument exists for the two objects, the
            argument is passed to both the Text and Rectangle instance.
        '''

        self._length = length
        self._base_settings['corner'] = corner
        self._base_settings['frame'] = frame
        self._base_settings['borderpad'] = borderpad
        self._base_settings['pad'] = pad

        if isinstance(length, u.Quantity):
            length = length.to(u.degree).value
        elif isinstance(length, u.Unit):
            length = length.to(u.degree)

        degrees_per_pixel = wcs_util.celestial_pixel_scale(self._wcs)

        length = length / degrees_per_pixel

        try:
            self._scalebar.remove()
        except:
            pass

        if isinstance(corner, six.string_types):
            corner = corners[corner]

        self._scalebar = AnchoredSizeBar(self._ax.transData, length, label, corner, \
                              pad=pad, borderpad=borderpad, sep=5, frameon=frame)

        self._ax.add_artist(self._scalebar)

        self.set(**kwargs)
Example #4
0
def add_sizebar(ax, size):
    asb = AnchoredSizeBar(ax.transData,
                          size,
                          str(size),
                          loc=8,
                          pad=0.1,
                          borderpad=0.5,
                          sep=5,
                          frameon=False)
    ax.add_artist(asb)
Example #5
0
    def show(self, length, label=None, corner='bottom right', frame=False, borderpad=0.4, pad=0.5, **kwargs):
        '''
        Overlay a scale bar on the image.

        Required Arguments:

            *length*:[ float ]
                The length of the scalebar

        Optional Keyword Arguments:

            *label*: [ string ]
                Label to place below the scalebar

            *corner*: [ integer ]
                Where to place the scalebar. Acceptable values are:, 'left',
                'right', 'top', 'bottom', 'top left', 'top right', 'bottom
                left' (default), 'bottom right'

            *frame*: [ True | False ]
                Whether to display a frame behind the scalebar (default is False)

        Advanced:

            Additional arguments are passed to the matplotlib Rectangle and
            Text classes. See the matplotlib documentation for more details.
            In cases where the same argument exists for the two objects, the
            argument is passed to both the Text and Rectangle instance.
        '''

        self._length = length
        self._base_settings['corner'] = corner
        self._base_settings['frame'] = frame
        self._base_settings['borderpad'] = borderpad
        self._base_settings['pad'] = pad

        pixel_scale = wcs_util.pixel_scale(self._wcs)

        length = length / pixel_scale

        try:
            self._scalebar.remove()
        except:
            pass

        if isinstance(corner, basestring):
            corner = corners[corner]

        self._scalebar = AnchoredSizeBar(self._ax.transData, length, label, corner, \
                              pad=pad, borderpad=borderpad, sep=5, frameon=frame)

        self._ax.add_artist(self._scalebar)

        self.set(**kwargs)
def draw_sizebar(ax):
    from mpl_toolkits.axes_grid.anchored_artists import AnchoredSizeBar
    # draw a horizontal bar with length of 0.1 in Data coordinate
    # (ax.transData) with a label underneath.
    asb = AnchoredSizeBar(ax.transData,
                          0.1,
                          r"1$^{\prime}$",
                          loc=8,
                          pad=0.1,
                          borderpad=0.5,
                          sep=5,
                          frameon=False)
    ax.add_artist(asb)
Example #7
0
 def plot_sections(sectionax, sectiondata):
     dx = load.dx
     x = np.arange(sectiondata.shape[1] * 1.0) * dx
     y = np.arange(sectiondata.shape[0] * 1.0) * dx
     X, Y = np.meshgrid(x, y)
     inmembrane = np.zeros_like(sectiondata)
     inmembrane[sectiondata > 0] = 1.0
     xmax = X[sectiondata > 0].max()
     xmin = X[sectiondata > 0].min()
     ymax = Y[sectiondata > 0].max()
     ymin = Y[sectiondata > 0].min()
     ymean = (Y * inmembrane).sum() / inmembrane.sum()
     xmean = (X * inmembrane).sum() / inmembrane.sum()
     yweighted = (Y * sectiondata).sum() / sectiondata.sum()
     xweighted = (X * sectiondata).sum() / sectiondata.sum()
     levels = [0.5, 1.5, 2.5, 3.5, 4.5]
     mycolors = ["w", "g", "r", "m", "c", "y"]
     for i in xrange(min(4, len(boxList))):
         if boxList[i] == 'Right':
             mycolors[1] = colorScale[i]
         if boxList[i] == 'Mid':
             mycolors[2] = colorScale[i]
         if boxList[i] == 'Left':
             mycolors[3] = colorScale[i]
     mycolors = colorScale[1:]
     if load.f_param4 == '97.00':
         mycolors = ['g', 'r', 'm', 'c']
     if load.f_param4 == '96.00':
         #rightup = 2, rightdown = 1, leftup = 4, leftdown = 3
         mycolors = ['g', 'r', 'c', 'm']
     #print mycolors
     # here we rotate so that the order of sections will match the
     # box plot.
     xdir, ydir = xweighted - xmean, yweighted - ymean
     xdir, ydir = xdir / np.sqrt(xdir**2 +
                                 ydir**2), ydir / np.sqrt(xdir**2 + ydir**2)
     extraxspace = .5
     extrayspace = 0
     Yrotated = X * xdir + Y * ydir
     Xrotated = X * ydir - Y * xdir
     sectionax.contourf(Xrotated,
                        Yrotated,
                        sectiondata,
                        levels=levels,
                        colors=mycolors)
     xmin = Xrotated[sectiondata > 0].min()
     xmax = Xrotated[sectiondata > 0].max()
     ymin = Yrotated[sectiondata > 0].min()
     ymax = Yrotated[sectiondata > 0].max()
     sectionax.set_xlim(xmin - extraxspace, xmax)
     sectionax.set_ylim(ymin - extrayspace, ymax)
     sectionax.set_aspect('equal')
     sectionax.set_frame_on(False)
     sectionax.axes.get_xaxis().set_visible(False)
     sectionax.axes.get_yaxis().set_visible(False)
     sectionax.add_artist(
         AnchoredSizeBar(
             sectionax.transData,
             1.00,  # length of the bar in the data reference
             "1$\mu$",  # label of the bar
             #bbox_to_anchor=(0.,0.,1.,1.),
             loc=8,  # 'best', # location (lower right)
             pad=-(ymax - ymin) / 2.0 + 0.4,
             borderpad=0.25,
             sep=3,
             frameon=False))
#patch = PolygonPatch(area1, edgecolor='k', alpha=1, fill=False)
#ax.add_patch(patch)

als_cut = np.ma.array(als1, mask=~mask)
#im1 = m1.pcolormesh(xx1, yy1, als_cut, cmap=plt.cm.jet, vmin=-0.2, vmax=0)
im1 = m1.pcolormesh(xx1, yy1, als_cut, cmap=plt.cm.jet, vmin=-0.2, vmax=1.2)
plt.colorbar(im1, orientation='horizontal')
#store the data
als_cut.dump(outals1)

# Then, I wanted to have a scale on the plot :
asb = AnchoredSizeBar(
    ax.transData,
    1000.,  # length of the bar in the data reference
    "1 km",  # label of the bar
    loc=2,  # location (lower right)
    pad=0.1,
    borderpad=0.25,
    sep=5,
    frameon=False)
ax.add_artist(asb)  # and finaly, we add the scale to the inset axis

fig1.tight_layout()
fig1.savefig(outpath + outname1)
#exit()

fig2 = plt.figure(figsize=(10, 10))
ax = fig2.add_subplot(111)
ax.set_title(title2, fontsize=28)

m2 = pr.plot.area_def2basemap(area_def2)
Example #9
0
class Scalebar(object):

    def __init__(self, parent):

        # Retrieve info from parent figure
        self._ax = parent._ax1
        self._wcs = parent._wcs
        self._figure = parent._figure

        # Save plotting parameters (required for @auto_refresh)
        self._parameters = parent._parameters

        # Initialize settings
        self._base_settings = {}
        self._scalebar_settings = {}
        self._label_settings = {}
        self._label_settings['fontproperties'] = FontProperties()

    # LAYOUT

    @auto_refresh
    def show(self, length, label=None, corner='bottom right', frame=False, borderpad=0.4, pad=0.5, **kwargs):
        '''
        Overlay a scale bar on the image.

        Parameters
        ----------

        length : float, or quantity
            The length of the scalebar in degrees, an angular quantity, or angular unit

        label : str, optional
            Label to place below the scalebar

        corner : int, optional
            Where to place the scalebar. Acceptable values are:, 'left',
            'right', 'top', 'bottom', 'top left', 'top right', 'bottom
            left' (default), 'bottom right'

        frame : str, optional
            Whether to display a frame behind the scalebar (default is False)

        kwargs
            Additional arguments are passed to the matplotlib Rectangle and
            Text classes. See the matplotlib documentation for more details.
            In cases where the same argument exists for the two objects, the
            argument is passed to both the Text and Rectangle instance.
        '''

        self._length = length
        self._base_settings['corner'] = corner
        self._base_settings['frame'] = frame
        self._base_settings['borderpad'] = borderpad
        self._base_settings['pad'] = pad

        if isinstance(length, u.Quantity):
            length = length.to(u.degree).value
        elif isinstance(length, u.Unit):
            length = length.to(u.degree)

        degrees_per_pixel = wcs_util.celestial_pixel_scale(self._wcs)

        length = length / degrees_per_pixel

        try:
            self._scalebar.remove()
        except:
            pass

        if isinstance(corner, six.string_types):
            corner = corners[corner]

        self._scalebar = AnchoredSizeBar(self._ax.transData, length, label, corner, \
                              pad=pad, borderpad=borderpad, sep=5, frameon=frame)

        self._ax.add_artist(self._scalebar)

        self.set(**kwargs)

    @auto_refresh
    def _remove(self):
        self._scalebar.remove()

    @auto_refresh
    def hide(self):
        '''
        Hide the scalebar.
        '''
        try:
            self._scalebar.remove()
        except:
            pass

    @auto_refresh
    def set_length(self, length):
        '''
        Set the length of the scale bar.
        '''
        self.show(length, **self._base_settings)
        self._set_scalebar_properties(**self._scalebar_settings)
        self._set_label_properties(**self._scalebar_settings)

    @auto_refresh
    def set_label(self, label):
        '''
        Set the label of the scale bar.
        '''
        self._set_label_properties(text=label)

    @auto_refresh
    def set_corner(self, corner):
        '''
        Set where to place the scalebar.

        Acceptable values are 'left', 'right', 'top', 'bottom', 'top left',
        'top right', 'bottom left' (default), and 'bottom right'.
        '''
        self._base_settings['corner'] = corner
        self.show(self._length, **self._base_settings)
        self._set_scalebar_properties(**self._scalebar_settings)
        self._set_label_properties(**self._scalebar_settings)

    @auto_refresh
    def set_frame(self, frame):
        '''
        Set whether to display a frame around the scalebar.
        '''
        self._base_settings['frame'] = frame
        self.show(self._length, **self._base_settings)
        self._set_scalebar_properties(**self._scalebar_settings)
        self._set_label_properties(**self._scalebar_settings)

    # APPEARANCE

    @auto_refresh
    def set_linewidth(self, linewidth):
        '''
        Set the linewidth of the scalebar, in points.
        '''
        self._set_scalebar_properties(linewidth=linewidth)

    @auto_refresh
    def set_linestyle(self, linestyle):
        '''
        Set the linestyle of the scalebar.

        Should be one of 'solid', 'dashed', 'dashdot', or 'dotted'.
        '''
        self._set_scalebar_properties(linestyle=linestyle)

    @auto_refresh
    def set_alpha(self, alpha):
        '''
        Set the alpha value (transparency).

        This should be a floating point value between 0 and 1.
        '''
        self._set_scalebar_properties(alpha=alpha)
        self._set_label_properties(alpha=alpha)

    @auto_refresh
    def set_color(self, color):
        '''
        Set the label and scalebar color.
        '''
        self._set_scalebar_properties(color=color)
        self._set_label_properties(color=color)

    @auto_refresh
    def set_font(self, family=None, style=None, variant=None, stretch=None, weight=None, size=None, fontproperties=None):
        '''
        Set the font of the tick labels

        Parameters
        ----------

        common: family, style, variant, stretch, weight, size, fontproperties

        Notes
        -----

        Default values are set by matplotlib or previously set values if
        set_font has already been called. Global default values can be set by
        editing the matplotlibrc file.
        '''

        if family:
            self._label_settings['fontproperties'].set_family(family)

        if style:
            self._label_settings['fontproperties'].set_style(style)

        if variant:
            self._label_settings['fontproperties'].set_variant(variant)

        if stretch:
            self._label_settings['fontproperties'].set_stretch(stretch)

        if weight:
            self._label_settings['fontproperties'].set_weight(weight)

        if size:
            self._label_settings['fontproperties'].set_size(size)

        if fontproperties:
            self._label_settings['fontproperties'] = fontproperties

        self._set_label_properties(fontproperties=self._label_settings['fontproperties'])

    @auto_refresh
    def _set_label_properties(self, **kwargs):
        '''
        Modify the scalebar label properties.

        All arguments are passed to the matplotlib Text class. See the
        matplotlib documentation for more details.
        '''
        for kwarg in kwargs:
            self._label_settings[kwarg] = kwargs[kwarg]
        self._scalebar.txt_label.get_children()[0].set(**kwargs)

    @auto_refresh
    def _set_scalebar_properties(self, **kwargs):
        '''
        Modify the scalebar properties.

        All arguments are passed to the matplotlib Rectangle class. See the
        matplotlib documentation for more details.
        '''
        for kwarg in kwargs:
            self._scalebar_settings[kwarg] = kwargs[kwarg]
        self._scalebar.size_bar.get_children()[0].set(**kwargs)

    @auto_refresh
    def set(self, **kwargs):
        '''
        Modify the scalebar and scalebar properties.

        All arguments are passed to the matplotlib Rectangle and Text classes.
        See the matplotlib documentation for more details. In cases where the
        same argument exists for the two objects, the argument is passed to
        both the Text and Rectangle instance.
        '''
        for kwarg in kwargs:
            kwargs_single = {kwarg: kwargs[kwarg]}
            try:
                self._set_label_properties(**kwargs_single)
            except AttributeError:
                pass
            try:
                self._set_scalebar_properties(**kwargs_single)
            except AttributeError:
                pass

    # DEPRECATED

    @auto_refresh
    def set_font_family(self, family):
        warnings.warn("scalebar.set_font_family is deprecated - use scalebar.set_font instead", DeprecationWarning)
        self.set_font(family=family)

    @auto_refresh
    def set_font_weight(self, weight):
        warnings.warn("scalebar.set_font_weight is deprecated - use scalebar.set_font instead", DeprecationWarning)
        self.set_font(weight=weight)

    @auto_refresh
    def set_font_size(self, size):
        warnings.warn("scalebar.set_font_size is deprecated - use scalebar.set_font instead", DeprecationWarning)
        self.set_font(size=size)

    @auto_refresh
    def set_font_style(self, style):
        warnings.warn("scalebar.set_font_style is deprecated - use scalebar.set_font instead", DeprecationWarning)
        self.set_font(style=style)
Example #10
0
class Scalebar(object):
    def __init__(self, parent):

        # Retrieve info from parent figure
        self._ax = parent._ax1
        self._wcs = parent._wcs
        self._figure = parent._figure

        # Save plotting parameters (required for @auto_refresh)
        self._parameters = parent._parameters

        # Initialize settings
        self._base_settings = {}
        self._scalebar_settings = {}
        self._label_settings = {}
        self._label_settings['fontproperties'] = FontProperties()

    # LAYOUT

    @auto_refresh
    def show(self,
             length,
             label=None,
             corner='bottom right',
             frame=False,
             borderpad=0.4,
             pad=0.5,
             **kwargs):
        '''
        Overlay a scale bar on the image.

        Parameters
        ----------

        length : float, or quantity
            The length of the scalebar in degrees, an angular quantity, or angular unit

        label : str, optional
            Label to place below the scalebar

        corner : int, optional
            Where to place the scalebar. Acceptable values are:, 'left',
            'right', 'top', 'bottom', 'top left', 'top right', 'bottom
            left' (default), 'bottom right'

        frame : str, optional
            Whether to display a frame behind the scalebar (default is False)

        kwargs
            Additional arguments are passed to the matplotlib Rectangle and
            Text classes. See the matplotlib documentation for more details.
            In cases where the same argument exists for the two objects, the
            argument is passed to both the Text and Rectangle instance.
        '''

        self._length = length
        self._base_settings['corner'] = corner
        self._base_settings['frame'] = frame
        self._base_settings['borderpad'] = borderpad
        self._base_settings['pad'] = pad

        if isinstance(length, u.Quantity):
            length = length.to(u.degree).value
        elif isinstance(length, u.Unit):
            length = length.to(u.degree)

        degrees_per_pixel = wcs_util.celestial_pixel_scale(self._wcs)

        length = length / degrees_per_pixel

        try:
            self._scalebar.remove()
        except:
            pass

        if isinstance(corner, six.string_types):
            corner = corners[corner]

        self._scalebar = AnchoredSizeBar(self._ax.transData, length, label, corner, \
                              pad=pad, borderpad=borderpad, sep=5, frameon=frame)

        self._ax.add_artist(self._scalebar)

        self.set(**kwargs)

    @auto_refresh
    def _remove(self):
        self._scalebar.remove()

    @auto_refresh
    def hide(self):
        '''
        Hide the scalebar.
        '''
        try:
            self._scalebar.remove()
        except:
            pass

    @auto_refresh
    def set_length(self, length):
        '''
        Set the length of the scale bar.
        '''
        self.show(length, **self._base_settings)
        self._set_scalebar_properties(**self._scalebar_settings)
        self._set_label_properties(**self._scalebar_settings)

    @auto_refresh
    def set_label(self, label):
        '''
        Set the label of the scale bar.
        '''
        self._set_label_properties(text=label)

    @auto_refresh
    def set_corner(self, corner):
        '''
        Set where to place the scalebar.

        Acceptable values are 'left', 'right', 'top', 'bottom', 'top left',
        'top right', 'bottom left' (default), and 'bottom right'.
        '''
        self._base_settings['corner'] = corner
        self.show(self._length, **self._base_settings)
        self._set_scalebar_properties(**self._scalebar_settings)
        self._set_label_properties(**self._scalebar_settings)

    @auto_refresh
    def set_frame(self, frame):
        '''
        Set whether to display a frame around the scalebar.
        '''
        self._base_settings['frame'] = frame
        self.show(self._length, **self._base_settings)
        self._set_scalebar_properties(**self._scalebar_settings)
        self._set_label_properties(**self._scalebar_settings)

    # APPEARANCE

    @auto_refresh
    def set_linewidth(self, linewidth):
        '''
        Set the linewidth of the scalebar, in points.
        '''
        self._set_scalebar_properties(linewidth=linewidth)

    @auto_refresh
    def set_linestyle(self, linestyle):
        '''
        Set the linestyle of the scalebar.

        Should be one of 'solid', 'dashed', 'dashdot', or 'dotted'.
        '''
        self._set_scalebar_properties(linestyle=linestyle)

    @auto_refresh
    def set_alpha(self, alpha):
        '''
        Set the alpha value (transparency).

        This should be a floating point value between 0 and 1.
        '''
        self._set_scalebar_properties(alpha=alpha)
        self._set_label_properties(alpha=alpha)

    @auto_refresh
    def set_color(self, color):
        '''
        Set the label and scalebar color.
        '''
        self._set_scalebar_properties(color=color)
        self._set_label_properties(color=color)

    @auto_refresh
    def set_font(self,
                 family=None,
                 style=None,
                 variant=None,
                 stretch=None,
                 weight=None,
                 size=None,
                 fontproperties=None):
        '''
        Set the font of the tick labels

        Parameters
        ----------

        common: family, style, variant, stretch, weight, size, fontproperties

        Notes
        -----

        Default values are set by matplotlib or previously set values if
        set_font has already been called. Global default values can be set by
        editing the matplotlibrc file.
        '''

        if family:
            self._label_settings['fontproperties'].set_family(family)

        if style:
            self._label_settings['fontproperties'].set_style(style)

        if variant:
            self._label_settings['fontproperties'].set_variant(variant)

        if stretch:
            self._label_settings['fontproperties'].set_stretch(stretch)

        if weight:
            self._label_settings['fontproperties'].set_weight(weight)

        if size:
            self._label_settings['fontproperties'].set_size(size)

        if fontproperties:
            self._label_settings['fontproperties'] = fontproperties

        self._set_label_properties(
            fontproperties=self._label_settings['fontproperties'])

    @auto_refresh
    def _set_label_properties(self, **kwargs):
        '''
        Modify the scalebar label properties.

        All arguments are passed to the matplotlib Text class. See the
        matplotlib documentation for more details.
        '''
        for kwarg in kwargs:
            self._label_settings[kwarg] = kwargs[kwarg]
        self._scalebar.txt_label.get_children()[0].set(**kwargs)

    @auto_refresh
    def _set_scalebar_properties(self, **kwargs):
        '''
        Modify the scalebar properties.

        All arguments are passed to the matplotlib Rectangle class. See the
        matplotlib documentation for more details.
        '''
        for kwarg in kwargs:
            self._scalebar_settings[kwarg] = kwargs[kwarg]
        self._scalebar.size_bar.get_children()[0].set(**kwargs)

    @auto_refresh
    def set(self, **kwargs):
        '''
        Modify the scalebar and scalebar properties.

        All arguments are passed to the matplotlib Rectangle and Text classes.
        See the matplotlib documentation for more details. In cases where the
        same argument exists for the two objects, the argument is passed to
        both the Text and Rectangle instance.
        '''
        for kwarg in kwargs:
            kwargs_single = {kwarg: kwargs[kwarg]}
            try:
                self._set_label_properties(**kwargs_single)
            except AttributeError:
                pass
            try:
                self._set_scalebar_properties(**kwargs_single)
            except AttributeError:
                pass

    # DEPRECATED

    @auto_refresh
    def set_font_family(self, family):
        warnings.warn(
            "scalebar.set_font_family is deprecated - use scalebar.set_font instead",
            DeprecationWarning)
        self.set_font(family=family)

    @auto_refresh
    def set_font_weight(self, weight):
        warnings.warn(
            "scalebar.set_font_weight is deprecated - use scalebar.set_font instead",
            DeprecationWarning)
        self.set_font(weight=weight)

    @auto_refresh
    def set_font_size(self, size):
        warnings.warn(
            "scalebar.set_font_size is deprecated - use scalebar.set_font instead",
            DeprecationWarning)
        self.set_font(size=size)

    @auto_refresh
    def set_font_style(self, style):
        warnings.warn(
            "scalebar.set_font_style is deprecated - use scalebar.set_font instead",
            DeprecationWarning)
        self.set_font(style=style)
Example #11
0
    def show(self,
             length,
             label=None,
             corner='bottom right',
             frame=False,
             borderpad=0.4,
             pad=0.5,
             **kwargs):
        '''
        Overlay a scale bar on the image.

        Required Arguments:

            *length*:[ float ]
                The length of the scalebar

        Optional Keyword Arguments:

            *label*: [ string ]
                Label to place below the scalebar

            *corner*: [ integer ]
                Where to place the scalebar. Acceptable values are:, 'left',
                'right', 'top', 'bottom', 'top left', 'top right', 'bottom
                left' (default), 'bottom right'

            *frame*: [ True | False ]
                Whether to display a frame behind the scalebar (default is False)

        Advanced:

            Additional arguments are passed to the matplotlib Rectangle and
            Text classes. See the matplotlib documentation for more details.
            In cases where the same argument exists for the two objects, the
            argument is passed to both the Text and Rectangle instance.
        '''

        self._length = length
        self._base_settings['corner'] = corner
        self._base_settings['frame'] = frame
        self._base_settings['borderpad'] = borderpad
        self._base_settings['pad'] = pad

        pixel_scale = wcs_util.pixel_scale(self._wcs)

        length = length / pixel_scale

        try:
            self._scalebar.remove()
        except:
            pass

        if isinstance(corner, basestring):
            corner = corners[corner]

        self._scalebar = AnchoredSizeBar(self._ax.transData, length, label, corner, \
                              pad=pad, borderpad=borderpad, sep=5, frameon=frame)

        self._ax.add_artist(self._scalebar)

        self.set(**kwargs)
Example #12
0
    def _updatescale(self,
                     ax,
                     scale=None,
                     color=None,
                     fontsize=None,
                     loc=8,
                     pad=0.1,
                     borderpad=0.5,
                     sep=5,
                     comoving=True):
        h = self.C['h']
        if scale is None:
            l = (self.extent[1] - self.extent[0]) * 0.2
        else:
            l = scale
            # always first put comoving distance to l
            if not comoving:
                l *= (1. + self.C['redshift'])
                l /= h

        if not comoving:
            # prefer integral distance numbers
            # for the type of distance of choice(comoving or proper)
            l /= (1. + self.C['redshift'])
            l *= h
            unit = ''
        else:
            unit = '/h'

        n, e = _fr10(l)
        l = numpy.floor(n) * 10**e

        if l > 500:
            l /= 1000.0
            l = int(l + 0.5)
            text = r"%g Mpc%s" % (l, unit)
            l *= 1000.0
        else:
            text = r"%g Kpc%s" % (l, unit)

        if not comoving:
            # but the bar is always drawn in comoving
            l *= (1. + self.C['redshift'])
            l /= h

        ret = AnchoredSizeBar(ax.transData,
                              l,
                              text,
                              loc=loc,
                              pad=pad,
                              borderpad=borderpad,
                              sep=sep,
                              frameon=False)

        if color is not None:
            for r in ret.size_bar.findobj(Rectangle):
                r.set_edgecolor(color)
            for t in ret.txt_label.findobj(Text):
                t.set_color(color)
        if fontsize is not None:
            for t in ret.txt_label.findobj(Text):
                t.set_fontsize(fontsize)

        return ret
Example #13
0
ax     = fig1.add_subplot(211)
ax.plot(.05, .9, 'w.', markersize=110, transform=ax.transAxes, markeredgecolor='k', markeredgewidth=2)
ax.text(.05, .9, title1, ha='center', va='center', transform=ax.transAxes, fontdict={'color':'k','size':55})
props = dict(boxstyle='round', facecolor='w', alpha=1)
ax.text(.87, .93, date1, ha='center', va='center', transform=ax.transAxes, fontdict={'color':'k','size':24},bbox=props)
m1 = pr.plot.area_def2basemap(area_def1)

#als data
xx1,yy1 = m1(lons1,lats1)
xx2,yy2 = m2(lons2,lats2)
als1 = np.ma.array(als1,mask=als1==-999)
im1 = m1.pcolormesh(xx1, yy1, als1, cmap=plt.cm.jet, vmin=0, vmax=1)
als1.mask = np.ma.nomask

# Then, I wanted to have a scale on the plot :
asb =  AnchoredSizeBar(ax.transData,100.,"100 m", loc=4,pad=.5, borderpad=.25, sep=5,frameon=True)
ax.add_artist(asb) # and finaly, we add the scale to the inset axis

#second plot
bx     = fig1.add_subplot(212)
bx.text(.87, .93, date2, ha='center', va='center', transform=bx.transAxes, fontdict={'color':'k','size':24},bbox=props)
m2 = pr.plot.area_def2basemap(area_def2)

als2 = np.ma.array(als2,mask=als2==-999)
im2 = m2.pcolormesh(xx2, yy2, als2, cmap=plt.cm.jet, vmin=0, vmax=1)
als2.mask = np.ma.nomask

# Then, I wanted to have a scale on the plot :
asb =  AnchoredSizeBar(bx.transData,100.,"100 m", loc=4,pad=.5, borderpad=.25, sep=5,frameon=True)
bx.add_artist(asb) # and finaly, we add the scale to the inset axis