Ejemplo n.º 1
0
    figsize_min = np.array((4.0,2.0)) # min length for width/height
    figsize_max = np.array((16.0,16.0)) # max length for width/height
    #figsize_min = rcParams['figure.figsize_min']
    #figsize_max = rcParams['figure.figsize_max']

    # Extract the aspect ratio of the array
    if isarray:
        nr,nc = arg.shape[:2]
        arr_ratio = float(nr)/nc
    else:
        arr_ratio = float(arg)

    # Height of user figure defaults
    fig_height = rcParams['figure.figsize'][1]

    # New size for the figure, keeping the aspect ratio of the caller
    newsize = np.array((fig_height/arr_ratio,fig_height))

    # Sanity checks, don't drop either dimension below figsize_min
    newsize /= min(1.0,*(newsize/figsize_min))

    # Avoid humongous windows as well
    newsize /= max(1.0,*(newsize/figsize_max))

    # Finally, if we have a really funky aspect ratio, break it but respect
    # the min/max dimensions (we don't want figures 10 feet tall!)
    newsize = np.clip(newsize,figsize_min,figsize_max)
    return newsize

docstring.interpd.update(Figure=artist.kwdoc(Figure))
Ejemplo n.º 2
0
    eg
    Example usage::
      w, h = figaspect(2.)
      fig = Figure(figsize=(w,h))
      ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
      ax.imshow(A, **kwargs)
      A = rand(5,3)
      w, h = figaspect(A)
      fig = Figure(figsize=(w,h))
      ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
      ax.imshow(A, **kwargs)
    Thanks to Fernando Perez for this function
    """
    isarray = hasattr(arg, 'shape')
    figsize_min = np.array((4.0, 2.0))  # min length for width/height
    figsize_max = np.array((16.0, 16.0))  # max length for width/height
    if isarray:
        nr, nc = arg.shape[:2]
        arr_ratio = float(nr) / nc
    else:
        arr_ratio = float(arg)
    fig_height = rcParams['figure.figsize'][1]
    newsize = np.array((fig_height / arr_ratio, fig_height))
    newsize /= min(1.0, *(newsize / figsize_min))
    newsize /= max(1.0, *(newsize / figsize_max))
    newsize = np.clip(newsize, figsize_min, figsize_max)
    return newsize


artist.kwdocd['Figure'] = artist.kwdoc(Figure)
Ejemplo n.º 3
0
        are the coordinates of the selected vertices.
        """
        pass

    def onpick(self, event):
        'When the line is picked, update the set of selected indicies.'
        if event.artist is not self.line: return

        for i in event.ind:
            if i in self.ind:
                self.ind.remove(i)
            else:
                self.ind.add(i)


        ind = list(self.ind)
        ind.sort()
        xdata, ydata = self.line.get_data()
        self.process_selected(ind, xdata[ind], ydata[ind])

lineStyles = Line2D._lineStyles
lineMarkers = MarkerStyle.markers
drawStyles = Line2D.drawStyles
fillStyles = MarkerStyle.fillstyles

docstring.interpd.update(Line2D = artist.kwdoc(Line2D))

# You can not set the docstring of an instancemethod,
# but you can on the underlying function.  Go figure.
docstring.dedent_interpd(Line2D.__init__)
Ejemplo n.º 4
0
        if dollar_count > 0 and dollar_count % 2 == 0:
            return True

        return False

    def set_fontproperties(self, fp):
        """
        Set the font properties that control the text

        ACCEPTS: a matplotlib.font_manager.FontProperties instance
        """
        if is_string_like(fp):
            fp = FontProperties(fp)
        self._fontproperties = fp

artist.kwdocd['Text'] = artist.kwdoc(Text)


class TextWithDash(Text):
    """
    This is basically a Text with a dash (drawn with a Line2D)
    before/after it. It is intended to be a drop-in replacement
    for Text, and should behave identically to Text when
    dashlength=0.0.

    The dash always comes between the point specified by
    set_position() and the text. When a dash exists, the
    text alignment arguments (horizontalalignment,
    verticalalignment) are ignored.

    dashlength is the length of the dash in canvas units.
Ejemplo n.º 5
0
    for row in xrange(rows):
        for col in xrange(cols):
            table.add_cell(row+offset, col,
                           width=colWidths[col], height=height,
                           text=cellText[row][col],
                           facecolor=cellColours[row][col],
                           loc=cellLoc)
    # Do column labels
    if colLabels is not None:
        for col in xrange(cols):
            table.add_cell(0, col,
                           width=colWidths[col], height=height,
                           text=colLabels[col], facecolor=colColours[col],
                           loc=colLoc)

    # Do row labels
    if rowLabels is not None:
        for row in xrange(rows):
            table.add_cell(row+offset, -1,
                           width=rowLabelWidth or 1e-15, height=height,
                           text=rowLabels[row], facecolor=rowColours[row],
                           loc=rowLoc)
        if rowLabelWidth == 0:
            table.auto_set_column_width(-1)

    ax.add_table(table)
    return table


artist.kwdocd['Table'] = artist.kwdoc(Table)
Ejemplo n.º 6
0
            return True

        return False

    def set_fontproperties(self, fp):
        """
        Set the font properties that control the text

        ACCEPTS: a matplotlib.font_manager.FontProperties instance
        """
        if is_string_like(fp):
            fp = FontProperties(fp)
        self._fontproperties = fp


artist.kwdocd["Text"] = artist.kwdoc(Text)


class TextWithDash(Text):
    """
    This is basically a :class:`~matplotlib.text.Text` with a dash
    (drawn with a :class:`~matplotlib.lines.Line2D`) before/after
    it. It is intended to be a drop-in replacement for
    :class:`~matplotlib.text.Text`, and should behave identically to
    it when *dashlength* = 0.0.

    The dash always comes between the point specified by
    :meth:`~matplotlib.text.Text.set_position` and the text. When a
    dash exists, the text alignment arguments (*horizontalalignment*,
    *verticalalignment*) are ignored.
Ejemplo n.º 7
0
                col,
                width=colWidths[col],
                height=height,
                text=cellText[row][col],
                facecolor=cellColours[row][col],
                loc=cellLoc,
            )
    if colLabels is not None:
        for col in xrange(cols):
            table.add_cell(
                0, col, width=colWidths[col], height=height, text=colLabels[col], facecolor=colColours[col], loc=colLoc
            )
    if rowLabels is not None:
        for row in xrange(rows):
            table.add_cell(
                row + offset,
                -1,
                width=rowLabelWidth or 1e-15,
                height=height,
                text=rowLabels[row],
                facecolor=rowColours[row],
                loc=rowLoc,
            )
        if rowLabelWidth == 0:
            table.auto_set_column_width(-1)
    ax.add_table(table)
    return table


artist.kwdocd["Table"] = artist.kwdoc(Table)
Ejemplo n.º 8
0
    figsize_max = np.array((16.0, 16.0))  # max length for width/height
    #figsize_min = rcParams['figure.figsize_min']
    #figsize_max = rcParams['figure.figsize_max']

    # Extract the aspect ratio of the array
    if isarray:
        nr, nc = arg.shape[:2]
        arr_ratio = float(nr) / nc
    else:
        arr_ratio = float(arg)

    # Height of user figure defaults
    fig_height = rcParams['figure.figsize'][1]

    # New size for the figure, keeping the aspect ratio of the caller
    newsize = np.array((fig_height / arr_ratio, fig_height))

    # Sanity checks, don't drop either dimension below figsize_min
    newsize /= min(1.0, *(newsize / figsize_min))

    # Avoid humongous windows as well
    newsize /= max(1.0, *(newsize / figsize_max))

    # Finally, if we have a really funky aspect ratio, break it but respect
    # the min/max dimensions (we don't want figures 10 feet tall!)
    newsize = np.clip(newsize, figsize_min, figsize_max)
    return newsize


docstring.interpd.update(Figure=artist.kwdoc(Figure))
Ejemplo n.º 9
0
    figsize_max = npy.array((16.0, 16.0))  # max length for width/height
    #figsize_min = rcParams['figure.figsize_min']
    #figsize_max = rcParams['figure.figsize_max']

    # Extract the aspect ratio of the array
    if isarray:
        nr, nc = arg.shape[:2]
        arr_ratio = float(nr) / nc
    else:
        arr_ratio = float(arg)

    # Height of user figure defaults
    fig_height = rcParams['figure.figsize'][1]

    # New size for the figure, keeping the aspect ratio of the caller
    newsize = npy.array((fig_height / arr_ratio, fig_height))

    # Sanity checks, don't drop either dimension below figsize_min
    newsize /= min(1.0, *(newsize / figsize_min))

    # Avoid humongous windows as well
    newsize /= max(1.0, *(newsize / figsize_max))

    # Finally, if we have a really funky aspect ratio, break it but respect
    # the min/max dimensions (we don't want figures 10 feet tall!)
    newsize = npy.clip(newsize, figsize_min, figsize_max)
    return newsize


artist.kwdocd['Figure'] = artist.kwdoc(Figure)
Ejemplo n.º 10
0
        """
        pass

    def onpick(self, event):
        """When the line is picked, update the set of selected indicies."""
        if event.artist is not self.line:
            return

        for i in event.ind:
            if i in self.ind:
                self.ind.remove(i)
            else:
                self.ind.add(i)

        ind = list(self.ind)
        ind.sort()
        xdata, ydata = self.line.get_data()
        self.process_selected(ind, xdata[ind], ydata[ind])


lineStyles = Line2D._lineStyles
lineMarkers = MarkerStyle.markers
drawStyles = Line2D.drawStyles
fillStyles = MarkerStyle.fillstyles

docstring.interpd.update(Line2D=artist.kwdoc(Line2D))

# You can not set the docstring of an instancemethod,
# but you can on the underlying function.  Go figure.
docstring.dedent_interpd(Line2D.__init__)
Ejemplo n.º 11
0
    figsize_max = np.array((16.0, 16.0))  # max length for width/height
    # figsize_min = rcParams['figure.figsize_min']
    # figsize_max = rcParams['figure.figsize_max']

    # Extract the aspect ratio of the array
    if isarray:
        nr, nc = arg.shape[:2]
        arr_ratio = float(nr) / nc
    else:
        arr_ratio = float(arg)

    # Height of user figure defaults
    fig_height = rcParams["figure.figsize"][1]

    # New size for the figure, keeping the aspect ratio of the caller
    newsize = np.array((fig_height / arr_ratio, fig_height))

    # Sanity checks, don't drop either dimension below figsize_min
    newsize /= min(1.0, *(newsize / figsize_min))

    # Avoid humongous windows as well
    newsize /= max(1.0, *(newsize / figsize_max))

    # Finally, if we have a really funky aspect ratio, break it but respect
    # the min/max dimensions (we don't want figures 10 feet tall!)
    newsize = np.clip(newsize, figsize_min, figsize_max)
    return newsize


artist.kwdocd["Figure"] = artist.kwdoc(Figure)
Ejemplo n.º 12
0
            return True

        return False

    def set_fontproperties(self, fp):
        """
        Set the font properties that control the text

        ACCEPTS: a matplotlib.font_manager.FontProperties instance
        """
        if is_string_like(fp):
            fp = FontProperties(fp)
        self._fontproperties = fp


artist.kwdocd['Text'] = artist.kwdoc(Text)


class TextWithDash(Text):
    """
    This is basically a Text with a dash (drawn with a Line2D)
    before/after it. It is intended to be a drop-in replacement
    for Text, and should behave identically to Text when
    dashlength=0.0.

    The dash always comes between the point specified by
    set_position() and the text. When a dash exists, the
    text alignment arguments (horizontalalignment,
    verticalalignment) are ignored.

    dashlength is the length of the dash in canvas units.
Ejemplo n.º 13
0
                           loc=cellLoc)
    # Do column labels
    if colLabels is not None:
        for col in xrange(cols):
            table.add_cell(0,
                           col,
                           width=colWidths[col],
                           height=height,
                           text=colLabels[col],
                           facecolor=colColours[col],
                           loc=colLoc)

    # Do row labels
    if rowLabels is not None:
        for row in xrange(rows):
            table.add_cell(row + offset,
                           -1,
                           width=rowLabelWidth or 1e-15,
                           height=height,
                           text=rowLabels[row],
                           facecolor=rowColours[row],
                           loc=rowLoc)
        if rowLabelWidth == 0:
            table.auto_set_column_width(-1)

    ax.add_table(table)
    return table


artist.kwdocd['Table'] = artist.kwdoc(Table)
Ejemplo n.º 14
0
                           loc=cellLoc)
    # Do column labels
    if colLabels is not None:
        for col in xrange(cols):
            table.add_cell(0,
                           col,
                           width=colWidths[col],
                           height=height,
                           text=colLabels[col],
                           facecolor=colColours[col],
                           loc=colLoc)

    # Do row labels
    if rowLabels is not None:
        for row in xrange(rows):
            table.add_cell(row + offset,
                           -1,
                           width=rowLabelWidth or 1e-15,
                           height=height,
                           text=rowLabels[row],
                           facecolor=rowColours[row],
                           loc=rowLoc)
        if rowLabelWidth == 0:
            table.auto_set_column_width(-1)

    ax.add_table(table)
    return table


docstring.interpd.update(Table=artist.kwdoc(Table))
Ejemplo n.º 15
0
    def process_selected(self, ind, xs, ys):
        """
        Default do nothing implementation of the process_selected method.

        ind are the indices of the selected vertices.  xs and ys are
        the coordinates of the selected vertices.
        """
        pass

    def onpick(self, event):
        'when the line is picked, update the set of selected indicies'
        if event.artist is not self.line: return

        for i in event.ind:
            if i in self.ind:
                self.ind.remove(i)
            else:
                self.ind.add(i)


        ind = list(self.ind)
        ind.sort()
        xdata, ydata = self.line.get_data()
        self.process_selected(ind, xdata[ind], ydata[ind])

lineStyles = Line2D._lineStyles
lineMarkers = Line2D._markers

artist.kwdocd['Line2D'] = artist.kwdoc(Line2D)
Ejemplo n.º 16
0
        *ind* are the indices of the selected vertices.  *xs* and *ys*
        are the coordinates of the selected vertices.
        """
        pass

    def onpick(self, event):
        'When the line is picked, update the set of selected indicies.'
        if event.artist is not self.line: return

        for i in event.ind:
            if i in self.ind:
                self.ind.remove(i)
            else:
                self.ind.add(i)


        ind = list(self.ind)
        ind.sort()
        xdata, ydata = self.line.get_data()
        self.process_selected(ind, xdata[ind], ydata[ind])

lineStyles = Line2D._lineStyles
lineMarkers = Line2D._markers
drawStyles = Line2D.drawStyles

artist.kwdocd['Line2D'] = artist.kwdoc(Line2D)

# You can not set the docstring of an instancemethod,
# but you can on the underlying function.  Go figure.
Line2D.__init__.im_func.__doc__ = dedent(Line2D.__init__.__doc__) % artist.kwdocd
Ejemplo n.º 17
0
    for row in xrange(rows):
        for col in xrange(cols):
            table.add_cell(row+offset, col,
                           width=colWidths[col], height=height,
                           text=cellText[row][col],
                           facecolor=cellColours[row][col],
                           loc=cellLoc)
    # Do column labels
    if colLabels is not None:
        for col in xrange(cols):
            table.add_cell(0, col,
                           width=colWidths[col], height=height,
                           text=colLabels[col], facecolor=colColours[col],
                           loc=colLoc)

    # Do row labels
    if rowLabels is not None:
        for row in xrange(rows):
            table.add_cell(row+offset, -1,
                           width=rowLabelWidth or 1e-15, height=height,
                           text=rowLabels[row], facecolor=rowColours[row],
                           loc=rowLoc)
        if rowLabelWidth == 0:
            table.auto_set_column_width(-1)

    ax.add_table(table)
    return table


docstring.interpd.update(Table=artist.kwdoc(Table))
Ejemplo n.º 18
0
        *ind* are the indices of the selected vertices.  *xs* and *ys*
        are the coordinates of the selected vertices.
        """
        pass

    def onpick(self, event):
        "When the line is picked, update the set of selected indicies."
        if event.artist is not self.line:
            return

        for i in event.ind:
            if i in self.ind:
                self.ind.remove(i)
            else:
                self.ind.add(i)

        ind = list(self.ind)
        ind.sort()
        xdata, ydata = self.line.get_data()
        self.process_selected(ind, xdata[ind], ydata[ind])


lineStyles = Line2D._lineStyles
lineMarkers = Line2D._markers

artist.kwdocd["Line2D"] = artist.kwdoc(Line2D)

# You can not set the docstring of an instancemethod,
# but you can on the underlying function.  Go figure.
Line2D.__init__.im_func.__doc__ = dedent(Line2D.__init__.__doc__) % artist.kwdocd