Python matplotlib.cbook.Bunch() Examples

The following are 20 code examples of matplotlib.cbook.Bunch(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.cbook , or try the search function .
Example #1
Source File: _base.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def start_pan(self, x, y, button):
        """
        Called when a pan operation has started.

        *x*, *y* are the mouse coordinates in display coords.
        button is the mouse button number:

        * 1: LEFT
        * 2: MIDDLE
        * 3: RIGHT

        .. note::

            Intended to be overridden by new projection types.

        """
        self._pan_start = cbook.Bunch(
            lim=self.viewLim.frozen(),
            trans=self.transData.frozen(),
            trans_inverse=self.transData.inverted().frozen(),
            bbox=self.bbox.frozen(),
            x=x,
            y=y) 
Example #2
Source File: polar.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def start_pan(self, x, y, button):
        angle = np.deg2rad(self._r_label_position.to_values()[4])
        mode = ''
        if button == 1:
            epsilon = np.pi / 45.0
            t, r = self.transData.inverted().transform_point((x, y))
            if t >= angle - epsilon and t <= angle + epsilon:
                mode = 'drag_r_labels'
        elif button == 3:
            mode = 'zoom'

        self._pan_start = cbook.Bunch(
            rmax          = self.get_rmax(),
            trans         = self.transData.frozen(),
            trans_inverse = self.transData.inverted().frozen(),
            r_label_angle = self._r_label_position.to_values()[4],
            x             = x,
            y             = y,
            mode          = mode
            ) 
Example #3
Source File: polar.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def start_pan(self, x, y, button):
        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 t >= angle - epsilon and t <= angle + epsilon:
                mode = 'drag_r_labels'
        elif button == 3:
            mode = 'zoom'

        self._pan_start = cbook.Bunch(
            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) 
Example #4
Source File: _base.py    From ImageFusion with MIT License 6 votes vote down vote up
def start_pan(self, x, y, button):
        """
        Called when a pan operation has started.

        *x*, *y* are the mouse coordinates in display coords.
        button is the mouse button number:

        * 1: LEFT
        * 2: MIDDLE
        * 3: RIGHT

        .. note::

            Intended to be overridden by new projection types.

        """
        self._pan_start = cbook.Bunch(
            lim=self.viewLim.frozen(),
            trans=self.transData.frozen(),
            trans_inverse=self.transData.inverted().frozen(),
            bbox=self.bbox.frozen(),
            x=x,
            y=y) 
Example #5
Source File: polar.py    From ImageFusion with MIT License 6 votes vote down vote up
def start_pan(self, x, y, button):
        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 t >= angle - epsilon and t <= angle + epsilon:
                mode = 'drag_r_labels'
        elif button == 3:
            mode = 'zoom'

        self._pan_start = cbook.Bunch(
            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
            ) 
Example #6
Source File: polar.py    From neural-network-animation with MIT License 6 votes vote down vote up
def start_pan(self, x, y, button):
        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 t >= angle - epsilon and t <= angle + epsilon:
                mode = 'drag_r_labels'
        elif button == 3:
            mode = 'zoom'

        self._pan_start = cbook.Bunch(
            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
            ) 
Example #7
Source File: _base.py    From neural-network-animation with MIT License 6 votes vote down vote up
def start_pan(self, x, y, button):
        """
        Called when a pan operation has started.

        *x*, *y* are the mouse coordinates in display coords.
        button is the mouse button number:

        * 1: LEFT
        * 2: MIDDLE
        * 3: RIGHT

        .. note::

            Intended to be overridden by new projection types.

        """
        self._pan_start = cbook.Bunch(
            lim=self.viewLim.frozen(),
            trans=self.transData.frozen(),
            trans_inverse=self.transData.inverted().frozen(),
            bbox=self.bbox.frozen(),
            x=x,
            y=y) 
Example #8
Source File: polar.py    From Computable with MIT License 6 votes vote down vote up
def start_pan(self, x, y, button):
        angle = np.deg2rad(self._r_label_position.to_values()[4])
        mode = ''
        if button == 1:
            epsilon = np.pi / 45.0
            t, r = self.transData.inverted().transform_point((x, y))
            if t >= angle - epsilon and t <= angle + epsilon:
                mode = 'drag_r_labels'
        elif button == 3:
            mode = 'zoom'

        self._pan_start = cbook.Bunch(
            rmax          = self.get_rmax(),
            trans         = self.transData.frozen(),
            trans_inverse = self.transData.inverted().frozen(),
            r_label_angle = self._r_label_position.to_values()[4],
            x             = x,
            y             = y,
            mode          = mode
            ) 
Example #9
Source File: dviread.py    From neural-network-animation with MIT License 5 votes vote down vote up
def _output(self):
        """
        Output the text and boxes belonging to the most recent page.
        page = dvi._output()
        """
        minx, miny, maxx, maxy = np.inf, np.inf, -np.inf, -np.inf
        maxy_pure = -np.inf
        for elt in self.text + self.boxes:
            if len(elt) == 4:   # box
                x,y,h,w = elt
                e = 0           # zero depth
            else:               # glyph
                x,y,font,g,w = elt
                h,e = font._height_depth_of(g)
            minx = min(minx, x)
            miny = min(miny, y - h)
            maxx = max(maxx, x + w)
            maxy = max(maxy, y + e)
            maxy_pure = max(maxy_pure, y)

        if self.dpi is None:
            # special case for ease of debugging: output raw dvi coordinates
            return mpl_cbook.Bunch(text=self.text, boxes=self.boxes,
                                   width=maxx-minx, height=maxy_pure-miny,
                                   descent=descent)

        d = self.dpi / (72.27 * 2**16) # from TeX's "scaled points" to dpi units
        if self.baseline is None:
            descent = (maxy - maxy_pure) * d
        else:
            descent = self.baseline

        text =  [ ((x-minx)*d, (maxy-y)*d - descent, f, g, w*d)
                  for (x,y,f,g,w) in self.text ]
        boxes = [ ((x-minx)*d, (maxy-y)*d - descent, h*d, w*d) for (x,y,h,w) in self.boxes ]

        return mpl_cbook.Bunch(text=text, boxes=boxes,
                               width=(maxx-minx)*d,
                               height=(maxy_pure-miny)*d,
                               descent=descent) 
Example #10
Source File: mathtext.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
        key = fontname, font_class, sym, fontsize, dpi
        bunch = self.glyphd.get(key)
        if bunch is not None:
            return bunch

        font, num, symbol_name, fontsize, slanted = \
            self._get_glyph(fontname, font_class, sym, fontsize, math)

        font.set_size(fontsize, dpi)
        glyph = font.load_char(
            num,
            flags=self.mathtext_backend.get_hinting_type())

        xmin, ymin, xmax, ymax = [val/64.0 for val in glyph.bbox]
        offset = self._get_offset(font, glyph, fontsize, dpi)
        metrics = Bunch(
            advance = glyph.linearHoriAdvance/65536.0,
            height  = glyph.height/64.0,
            width   = glyph.width/64.0,
            xmin    = xmin,
            xmax    = xmax,
            ymin    = ymin+offset,
            ymax    = ymax+offset,
            # iceberg is the equivalent of TeX's "height"
            iceberg = glyph.horiBearingY/64.0 + offset,
            slanted = slanted
            )

        result = self.glyphd[key] = Bunch(
            font            = font,
            fontsize        = fontsize,
            postscript_name = font.postscript_name,
            metrics         = metrics,
            symbol_name     = symbol_name,
            num             = num,
            glyph           = glyph,
            offset          = offset
            )
        return result 
Example #11
Source File: mathtext.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def get_results(self, box, used_characters):
        ship(0, 0, box)
        svg_elements = Bunch(svg_glyphs = self.svg_glyphs,
                             svg_rects = self.svg_rects)
        return (self.width,
                self.height + self.depth,
                self.depth,
                svg_elements,
                used_characters) 
Example #12
Source File: backend_driver_sgskip.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def parse_options():
    doc = (__doc__ and __doc__.split('\n\n')) or "  "
    op = OptionParser(description=doc[0].strip(),
                      usage='%prog [options] [--] [backends and switches]',
                      #epilog='\n'.join(doc[1:])  # epilog not supported on my python2.4 machine: JDH
                      )
    op.disable_interspersed_args()
    op.set_defaults(dirs='pylab,api,units,mplot3d',
                    clean=False, coverage=False, valgrind=False)
    op.add_option('-d', '--dirs', '--directories', type='string',
                  dest='dirs', help=dedent('''
      Run only the tests in these directories; comma-separated list of
      one or more of: pylab (or pylab_examples), api, units, mplot3d'''))
    op.add_option('-b', '--backends', type='string', dest='backends',
                  help=dedent('''
      Run tests only for these backends; comma-separated list of
      one or more of: agg, ps, svg, pdf, template, cairo,
      Default is everything except cairo.'''))
    op.add_option('--clean', action='store_true', dest='clean',
                  help='Remove result directories, run no tests')
    op.add_option('-c', '--coverage', action='store_true', dest='coverage',
                  help='Run in coverage.py')
    op.add_option('-v', '--valgrind', action='store_true', dest='valgrind',
                  help='Run in valgrind')

    options, args = op.parse_args()
    switches = [x for x in args if x.startswith('--')]
    backends = [x.lower() for x in args if not x.startswith('--')]
    if options.backends:
        backends += [be.lower() for be in options.backends.split(',')]

    result = Bunch(
        dirs=options.dirs.split(','),
        backends=backends or ['agg', 'ps', 'svg', 'pdf', 'template'],
        clean=options.clean,
        coverage=options.coverage,
        valgrind=options.valgrind,
        switches=switches)
    if 'pylab_examples' in result.dirs:
        result.dirs[result.dirs.index('pylab_examples')] = 'pylab'
    return result 
Example #13
Source File: dviread.py    From neural-network-animation with MIT License 5 votes vote down vote up
def _finalize_packet(self):
        self._chars[self._packet_char] = mpl_cbook.Bunch(
            text=self.text, boxes=self.boxes, width = self._packet_width)
        self.state = _dvistate.outer 
Example #14
Source File: dviread.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _finalize_packet(self):
        self._chars[self._packet_char] = mpl_cbook.Bunch(
            text=self.text, boxes=self.boxes, width = self._packet_width)
        self.state = _dvistate.outer 
Example #15
Source File: dviread.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _output(self):
        """
        Output the text and boxes belonging to the most recent page.
        page = dvi._output()
        """
        minx, miny, maxx, maxy = np.inf, np.inf, -np.inf, -np.inf
        maxy_pure = -np.inf
        for elt in self.text + self.boxes:
            if len(elt) == 4:   # box
                x,y,h,w = elt
                e = 0           # zero depth
            else:               # glyph
                x,y,font,g,w = elt
                h,e = font._height_depth_of(g)
            minx = min(minx, x)
            miny = min(miny, y - h)
            maxx = max(maxx, x + w)
            maxy = max(maxy, y + e)
            maxy_pure = max(maxy_pure, y)

        if self.dpi is None:
            # special case for ease of debugging: output raw dvi coordinates
            return mpl_cbook.Bunch(text=self.text, boxes=self.boxes,
                                   width=maxx-minx, height=maxy_pure-miny,
                                   descent=descent)

        d = self.dpi / (72.27 * 2**16) # from TeX's "scaled points" to dpi units
        if self.baseline is None:
            descent = (maxy - maxy_pure) * d
        else:
            descent = self.baseline

        text =  [ ((x-minx)*d, (maxy-y)*d - descent, f, g, w*d)
                  for (x,y,f,g,w) in self.text ]
        boxes = [ ((x-minx)*d, (maxy-y)*d - descent, h*d, w*d) for (x,y,h,w) in self.boxes ]

        return mpl_cbook.Bunch(text=text, boxes=boxes,
                               width=(maxx-minx)*d,
                               height=(maxy_pure-miny)*d,
                               descent=descent) 
Example #16
Source File: dviread.py    From Computable with MIT License 5 votes vote down vote up
def _finalize_packet(self):
        self._chars[self._packet_char] = mpl_cbook.Bunch(
            text=self.text, boxes=self.boxes, width = self._packet_width)
        self.state = _dvistate.outer 
Example #17
Source File: dviread.py    From Computable with MIT License 5 votes vote down vote up
def _output(self):
        """
        Output the text and boxes belonging to the most recent page.
        page = dvi._output()
        """
        minx, miny, maxx, maxy = np.inf, np.inf, -np.inf, -np.inf
        maxy_pure = -np.inf
        for elt in self.text + self.boxes:
            if len(elt) == 4:   # box
                x,y,h,w = elt
                e = 0           # zero depth
            else:               # glyph
                x,y,font,g,w = elt
                h,e = font._height_depth_of(g)
            minx = min(minx, x)
            miny = min(miny, y - h)
            maxx = max(maxx, x + w)
            maxy = max(maxy, y + e)
            maxy_pure = max(maxy_pure, y)

        if self.dpi is None:
            # special case for ease of debugging: output raw dvi coordinates
            return mpl_cbook.Bunch(text=self.text, boxes=self.boxes,
                                   width=maxx-minx, height=maxy_pure-miny,
                                   descent=descent)

        d = self.dpi / (72.27 * 2**16) # from TeX's "scaled points" to dpi units
        if self.baseline is None:
            descent = (maxy - maxy_pure) * d
        else:
            descent = self.baseline

        text =  [ ((x-minx)*d, (maxy-y)*d - descent, f, g, w*d)
                  for (x,y,f,g,w) in self.text ]
        boxes = [ ((x-minx)*d, (maxy-y)*d - descent, h*d, w*d) for (x,y,h,w) in self.boxes ]

        return mpl_cbook.Bunch(text=text, boxes=boxes,
                               width=(maxx-minx)*d,
                               height=(maxy_pure-miny)*d,
                               descent=descent) 
Example #18
Source File: dviread.py    From neural-network-animation with MIT License 4 votes vote down vote up
def _register(self, words):
        """Register a font described by "words".

        The format is, AFAIK: texname fontname [effects and filenames]
        Effects are PostScript snippets like ".177 SlantFont",
        filenames begin with one or two less-than signs. A filename
        ending in enc is an encoding file, other filenames are font
        files. This can be overridden with a left bracket: <[foobar
        indicates an encoding file named foobar.

        There is some difference between <foo.pfb and <<bar.pfb in
        subsetting, but I have no example of << in my TeX installation.
        """

        # If the map file specifies multiple encodings for a font, we
        # follow pdfTeX in choosing the last one specified. Such
        # entries are probably mistakes but they have occurred.
        # http://tex.stackexchange.com/questions/10826/
        # http://article.gmane.org/gmane.comp.tex.pdftex/4914

        texname, psname = words[:2]
        effects, encoding, filename = '', None, None
        for word in words[2:]:
            if not word.startswith('<'):
                effects = word
            else:
                word = word.lstrip('<')
                if word.startswith('[') or word.endswith('.enc'):
                    if encoding is not None:
                        matplotlib.verbose.report(
                            'Multiple encodings for %s = %s'
                            % (texname, psname), 'debug')
                    if word.startswith('['):
                        encoding = word[1:]
                    else:
                        encoding = word
                else:
                    assert filename is None
                    filename = word

        eff = effects.split()
        effects = {}
        try:
            effects['slant'] = float(eff[eff.index('SlantFont')-1])
        except ValueError:
            pass
        try:
            effects['extend'] = float(eff[eff.index('ExtendFont')-1])
        except ValueError:
            pass

        self._font[texname] = mpl_cbook.Bunch(
            texname=texname, psname=psname, effects=effects,
            encoding=encoding, filename=filename) 
Example #19
Source File: dviread.py    From matplotlib-4-abaqus with MIT License 4 votes vote down vote up
def _register(self, words):
        """Register a font described by "words".

        The format is, AFAIK: texname fontname [effects and filenames]
        Effects are PostScript snippets like ".177 SlantFont",
        filenames begin with one or two less-than signs. A filename
        ending in enc is an encoding file, other filenames are font
        files. This can be overridden with a left bracket: <[foobar
        indicates an encoding file named foobar.

        There is some difference between <foo.pfb and <<bar.pfb in
        subsetting, but I have no example of << in my TeX installation.
        """

        # If the map file specifies multiple encodings for a font, we
        # follow pdfTeX in choosing the last one specified. Such
        # entries are probably mistakes but they have occurred.
        # http://tex.stackexchange.com/questions/10826/
        # http://article.gmane.org/gmane.comp.tex.pdftex/4914

        texname, psname = words[:2]
        effects, encoding, filename = '', None, None
        for word in words[2:]:
            if not word.startswith('<'):
                effects = word
            else:
                word = word.lstrip('<')
                if word.startswith('[') or word.endswith('.enc'):
                    if encoding is not None:
                        matplotlib.verbose.report(
                            'Multiple encodings for %s = %s'
                            % (texname, psname), 'debug')
                    if word.startswith('['):
                        encoding = word[1:]
                    else:
                        encoding = word
                else:
                    assert filename is None
                    filename = word

        eff = effects.split()
        effects = {}
        try:
            effects['slant'] = float(eff[eff.index('SlantFont')-1])
        except ValueError:
            pass
        try:
            effects['extend'] = float(eff[eff.index('ExtendFont')-1])
        except ValueError:
            pass

        self._font[texname] = mpl_cbook.Bunch(
            texname=texname, psname=psname, effects=effects,
            encoding=encoding, filename=filename) 
Example #20
Source File: dviread.py    From Computable with MIT License 4 votes vote down vote up
def _register(self, words):
        """Register a font described by "words".

        The format is, AFAIK: texname fontname [effects and filenames]
        Effects are PostScript snippets like ".177 SlantFont",
        filenames begin with one or two less-than signs. A filename
        ending in enc is an encoding file, other filenames are font
        files. This can be overridden with a left bracket: <[foobar
        indicates an encoding file named foobar.

        There is some difference between <foo.pfb and <<bar.pfb in
        subsetting, but I have no example of << in my TeX installation.
        """

        # If the map file specifies multiple encodings for a font, we
        # follow pdfTeX in choosing the last one specified. Such
        # entries are probably mistakes but they have occurred.
        # http://tex.stackexchange.com/questions/10826/
        # http://article.gmane.org/gmane.comp.tex.pdftex/4914

        texname, psname = words[:2]
        effects, encoding, filename = '', None, None
        for word in words[2:]:
            if not word.startswith('<'):
                effects = word
            else:
                word = word.lstrip('<')
                if word.startswith('[') or word.endswith('.enc'):
                    if encoding is not None:
                        matplotlib.verbose.report(
                            'Multiple encodings for %s = %s'
                            % (texname, psname), 'debug')
                    if word.startswith('['):
                        encoding = word[1:]
                    else:
                        encoding = word
                else:
                    assert filename is None
                    filename = word

        eff = effects.split()
        effects = {}
        try:
            effects['slant'] = float(eff[eff.index('SlantFont')-1])
        except ValueError:
            pass
        try:
            effects['extend'] = float(eff[eff.index('ExtendFont')-1])
        except ValueError:
            pass

        self._font[texname] = mpl_cbook.Bunch(
            texname=texname, psname=psname, effects=effects,
            encoding=encoding, filename=filename)