Exemplo n.º 1
0
    def _render_on_subplot(self, subplot):
        """
        TESTS::

            sage: x,y = var('x,y')
            sage: P=plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
        """
        options = self.options()
        quiver_options = options.copy()
        quiver_options.pop('plot_points')
        subplot.quiver(self.xpos_array, self.ypos_array, self.xvec_array, self.yvec_array, angles='xy', **quiver_options)
Exemplo n.º 2
0
    def _render_on_subplot(self, subplot):
        """
        TESTS::

            sage: x,y = var('x,y')
            sage: P=plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
        """
        options = self.options()
        quiver_options = options.copy()
        quiver_options.pop('plot_points')
        subplot.quiver(self.xpos_array, self.ypos_array, self.xvec_array, self.yvec_array, angles='xy', **quiver_options)
Exemplo n.º 3
0
    def _render_on_subplot(self, subplot):
        """
        TESTS::

            sage: x, y = var('x y')
            sage: P = streamline_plot((sin(x), cos(y)), (x,-3,3), (y,-3,3))
        """
        options = self.options()
        streamplot_options = options.copy()
        streamplot_options.pop('plot_points')
        subplot.streamplot(self.xpos_array, self.ypos_array, self.xvec_array,
                           self.yvec_array, **streamplot_options)
Exemplo n.º 4
0
    def _render_on_subplot(self, subplot):
        """
        TESTS::

            sage: x, y = var('x y')
            sage: P = streamline_plot((sin(x), cos(y)), (x,-3,3), (y,-3,3))
        """
        options = self.options()
        streamplot_options = options.copy()
        streamplot_options.pop('plot_points')
        subplot.streamplot(self.xpos_array, self.ypos_array,
                       self.xvec_array, self.yvec_array,
                       **streamplot_options)
Exemplo n.º 5
0
    def _render_on_subplot(self, subplot):
        """
        TESTS::

            sage: matrix_plot(random_matrix(RDF, 50), cmap='jet')
        """
        options = self.options()
        cmap = get_cmap(options.pop('cmap', None))
        origin = options['origin']

        norm = options['norm']

        if norm == 'value':
            import matplotlib
            norm = matplotlib.colors.NoNorm()

        if options['subdivisions']:
            subdiv_options = options['subdivision_options']
            if isinstance(subdiv_options['boundaries'], (list, tuple)):
                rowsub, colsub = subdiv_options['boundaries']
            else:
                rowsub = subdiv_options['boundaries']
                colsub = subdiv_options['boundaries']
            if isinstance(subdiv_options['style'], (list, tuple)):
                rowstyle, colstyle = subdiv_options['style']
            else:
                rowstyle = subdiv_options['style']
                colstyle = subdiv_options['style']
            if rowstyle is None:
                rowstyle = dict()
            if colstyle is None:
                colstyle = dict()

            # Make line objects for subdivisions
            from line import line2d
            lim = self.get_minmax_data()
            # First draw horizontal lines representing row subdivisions
            for y in rowsub:
                l = line2d([(lim['xmin'], y - 0.5), (lim['xmax'], y - 0.5)],
                           **rowstyle)[0]
                l._render_on_subplot(subplot)
            for x in colsub:
                l = line2d([(x - 0.5, lim['ymin']), (x - 0.5, lim['ymax'])],
                           **colstyle)[0]
                l._render_on_subplot(subplot)

        if hasattr(self.xy_data_array, 'tocoo'):
            # Sparse matrix -- use spy
            opts = options.copy()
            for opt in [
                    'vmin', 'vmax', 'norm', 'origin', 'subdivisions',
                    'subdivision_options', 'colorbar', 'colorbar_options'
            ]:
                del opts[opt]
            if origin == 'lower':
                subplot.spy(self.xy_data_array.tocsr()[::-1], **opts)
            else:
                subplot.spy(self.xy_data_array, **opts)
        else:
            opts = dict(cmap=cmap,
                        interpolation='nearest',
                        aspect='equal',
                        norm=norm,
                        vmin=options['vmin'],
                        vmax=options['vmax'],
                        origin=origin,
                        zorder=options.get('zorder', None))
            image = subplot.imshow(self.xy_data_array, **opts)

            if options.get('colorbar', False):
                colorbar_options = options['colorbar_options']
                from matplotlib import colorbar
                cax, kwds = colorbar.make_axes_gridspec(
                    subplot, **colorbar_options)
                cb = colorbar.Colorbar(cax, image, **kwds)

        if origin == 'upper':
            subplot.xaxis.tick_top()
        elif origin == 'lower':
            subplot.xaxis.tick_bottom()
        subplot.xaxis.set_ticks_position(
            'both')  #only tick marks, not tick labels
Exemplo n.º 6
0
    def _render_on_subplot(self, subplot):
        """
        TESTS::

            sage: matrix_plot(random_matrix(RDF, 50), cmap='jet')
            Graphics object consisting of 1 graphics primitive
        """
        options = self.options()
        cmap = get_cmap(options.pop('cmap',None))
        origin=options['origin']

        norm=options['norm']

        if norm=='value':
            import matplotlib
            norm=matplotlib.colors.NoNorm()

        if options['subdivisions']:
            subdiv_options=options['subdivision_options']
            if isinstance(subdiv_options['boundaries'], (list, tuple)):
                rowsub,colsub=subdiv_options['boundaries']
            else:
                rowsub=subdiv_options['boundaries']
                colsub=subdiv_options['boundaries']
            if isinstance(subdiv_options['style'], (list, tuple)):
                rowstyle,colstyle=subdiv_options['style']
            else:
                rowstyle=subdiv_options['style']
                colstyle=subdiv_options['style']
            if rowstyle is None:
                rowstyle=dict()
            if colstyle is None:
                colstyle=dict()

            # Make line objects for subdivisions
            from line import line2d
            lim=self.get_minmax_data()
            # First draw horizontal lines representing row subdivisions
            for y in rowsub:
                l=line2d([(lim['xmin'],y-0.5), (lim['xmax'],y-0.5)], **rowstyle)[0]
                l._render_on_subplot(subplot)
            for x in colsub:
                l=line2d([(x-0.5, lim['ymin']), (x-0.5, lim['ymax'])], **colstyle)[0]
                l._render_on_subplot(subplot)

        if hasattr(self.xy_data_array, 'tocoo'):
            # Sparse matrix -- use spy
            opts=options.copy()
            for opt in ['vmin', 'vmax', 'norm', 'origin','subdivisions','subdivision_options',
                        'colorbar','colorbar_options']:
                del opts[opt]
            if origin=='lower':
                subplot.spy(self.xy_data_array.tocsr()[::-1], **opts)
            else:
                subplot.spy(self.xy_data_array, **opts)
        else:
            opts = dict(cmap=cmap, interpolation='nearest', aspect='equal',
                      norm=norm, vmin=options['vmin'], vmax=options['vmax'],
                      origin=origin,zorder=options.get('zorder',None))
            image=subplot.imshow(self.xy_data_array, **opts)

            if options.get('colorbar', False):
                colorbar_options = options['colorbar_options']
                from matplotlib import colorbar
                cax,kwds=colorbar.make_axes_gridspec(subplot,**colorbar_options)
                cb=colorbar.Colorbar(cax,image, **kwds)

        if origin=='upper':
            subplot.xaxis.tick_top()
        elif origin=='lower':
            subplot.xaxis.tick_bottom()
        subplot.xaxis.set_ticks_position('both') #only tick marks, not tick labels
Exemplo n.º 7
0
    def _render_on_subplot(self, subplot):
        """
        TESTS::

            sage: matrix_plot(random_matrix(RDF, 50), cmap='jet')
        """
        options = self.options()
        cmap = get_cmap(options.pop("cmap", None))
        origin = options["origin"]

        norm = options["norm"]

        if norm == "value":
            import matplotlib

            norm = matplotlib.colors.NoNorm()

        if options["subdivisions"]:
            subdiv_options = options["subdivision_options"]
            if isinstance(subdiv_options["boundaries"], (list, tuple)):
                rowsub, colsub = subdiv_options["boundaries"]
            else:
                rowsub = subdiv_options["boundaries"]
                colsub = subdiv_options["boundaries"]
            if isinstance(subdiv_options["style"], (list, tuple)):
                rowstyle, colstyle = subdiv_options["style"]
            else:
                rowstyle = subdiv_options["style"]
                colstyle = subdiv_options["style"]
            if rowstyle is None:
                rowstyle = dict()
            if colstyle is None:
                colstyle = dict()

            # Make line objects for subdivisions
            from line import line2d

            lim = self.get_minmax_data()
            # First draw horizontal lines representing row subdivisions
            for y in rowsub:
                l = line2d([(lim["xmin"], y - 0.5), (lim["xmax"], y - 0.5)], **rowstyle)[0]
                l._render_on_subplot(subplot)
            for x in colsub:
                l = line2d([(x - 0.5, lim["ymin"]), (x - 0.5, lim["ymax"])], **colstyle)[0]
                l._render_on_subplot(subplot)

        if hasattr(self.xy_data_array, "tocoo"):
            # Sparse matrix -- use spy
            opts = options.copy()
            for opt in [
                "vmin",
                "vmax",
                "norm",
                "origin",
                "subdivisions",
                "subdivision_options",
                "colorbar",
                "colorbar_options",
            ]:
                del opts[opt]
            if origin == "lower":
                subplot.spy(self.xy_data_array.tocsr()[::-1], **opts)
            else:
                subplot.spy(self.xy_data_array, **opts)
        else:
            opts = dict(
                cmap=cmap,
                interpolation="nearest",
                aspect="equal",
                norm=norm,
                vmin=options["vmin"],
                vmax=options["vmax"],
                origin=origin,
                zorder=options.get("zorder", None),
            )
            image = subplot.imshow(self.xy_data_array, **opts)

            if options.get("colorbar", False):
                colorbar_options = options["colorbar_options"]
                from matplotlib import colorbar

                cax, kwds = colorbar.make_axes_gridspec(subplot, **colorbar_options)
                cb = colorbar.Colorbar(cax, image, **kwds)

        if origin == "upper":
            subplot.xaxis.tick_top()
        elif origin == "lower":
            subplot.xaxis.tick_bottom()
        subplot.xaxis.set_ticks_position("both")  # only tick marks, not tick labels