예제 #1
0
    def plot_known(self):
        r"""
        TESTS::

            sage: from ore_algebra import *
            sage: from ore_algebra.analytic.function import DFiniteFunction
            sage: DiffOps, x, Dx = DifferentialOperators()

            sage: f = DFiniteFunction((x^2 + 1)*Dx^2 + 2*x*Dx, [0, 1])
            sage: f(-10, 100) # long time
            [-1.4711276743037345918528755717...]
            sage: f.approx(5, post_transform=Dx) # long time
            [0.038461538461538...]
            sage: f.plot_known() # long time
            Graphics object consisting of ... graphics primitives
        """
        g = plot.Graphics()
        for center, polys in self._polys.iteritems():
            center, rad = self._disk(Point(center, self.dop))
            xrange = (center - rad).mid(), (center + rad).mid()
            for i, a in enumerate(polys):
                # color palette copied from sage.plot.plot.plot
                color = plot.Color((0.66666 + i * 0.61803) % 1,
                                   1,
                                   0.4,
                                   space='hsl')
                Balls = a.pol.base_ring()
                g += plot.plot(lambda x: a.pol(Balls(x)).mid(),
                               xrange,
                               color=color)
                g += plot.text(str(a.prec), (center, a.pol(center).mid()),
                               color=color)
        for point, ini in self._inivecs.iteritems():
            g += plot.point2d((point, 0), size=50)
        return g
예제 #2
0
    def plot(self, cell_colors=None, **kwds):
        """
        Return a graphical representation for 2-dimensional Voronoi diagrams.

        INPUT:

        - ``cell_colors`` -- (default: ``None``) provide the colors for the cells, either as
          dictionary. Randomly colored cells are provided with ``None``.
        - ``**kwds`` -- optional keyword parameters, passed on as arguments for
          plot().

        OUTPUT:

        A graphics object.

        EXAMPLES::

            sage: P = [[0.671, 0.650], [0.258, 0.767], [0.562, 0.406], [0.254, 0.709], [0.493, 0.879]]

            sage: V = VoronoiDiagram(P); S=V.plot()
            sage: show(S, xmin=0, xmax=1, ymin=0, ymax=1, aspect_ratio=1, axes=false)

            sage: S=V.plot(cell_colors={0:'red', 1:'blue', 2:'green', 3:'white', 4:'yellow'})
            sage: show(S, xmin=0, xmax=1, ymin=0, ymax=1, aspect_ratio=1, axes=false)

            sage: S=V.plot(cell_colors=['red','blue','red','white', 'white'])
            sage: show(S, xmin=0, xmax=1, ymin=0, ymax=1, aspect_ratio=1, axes=false)

            sage: S=V.plot(cell_colors='something else')
            Traceback (most recent call last):
            ...
            AssertionError: 'cell_colors' must be a list or a dictionary


        Trying to plot a Voronoi diagram of dimension other than 2 gives an
        error::

            sage: VoronoiDiagram([[1, 2, 3], [6, 5, 4]]).plot()
            Traceback (most recent call last):
            ...
            NotImplementedError: Plotting of 3-dimensional Voronoi diagrams not
            implemented
        """

        if self.ambient_dim() == 2:
            S = line([])

            if cell_colors is None:
                from random import shuffle
                cell_colors = rainbow(self._n)
                shuffle(cell_colors)
            else:
                if not (isinstance(cell_colors, list) or (isinstance(cell_colors, dict))):
                    raise AssertionError("'cell_colors' must be a list or a dictionary")
            for i, p in enumerate(self._P):
                col = cell_colors[i]
                S += (self.regions()[p]).render_solid(color=col, zorder=1)
                S += point(p, color=col, pointsize=10, zorder=3)
                S += point(p, color='black', pointsize=20, zorder=2)
            return plot(S, **kwds)
        raise NotImplementedError('Plotting of ' + str(self.ambient_dim()) +
                                  '-dimensional Voronoi diagrams not' +
                                  ' implemented')
예제 #3
0
    def plot(self, cell_colors=None, **kwds):
        """
        Return a graphical representation for 2-dimensional Voronoi diagrams.

        INPUT:

        - ``cell_colors`` -- (default: ``None``) provide the colors for the cells, either as
          dictionary. Randomly colored cells are provided with ``None``.
        - ``**kwds`` -- optional keyword parameters, passed on as arguments for
          plot().

        OUTPUT:

        A graphics object.

        EXAMPLES::

            sage: P = [[0.671, 0.650], [0.258, 0.767], [0.562, 0.406], [0.254, 0.709], [0.493, 0.879]]

            sage: V = VoronoiDiagram(P); S=V.plot()
            sage: show(S, xmin=0, xmax=1, ymin=0, ymax=1, aspect_ratio=1, axes=false)

            sage: S=V.plot(cell_colors={0:'red', 1:'blue', 2:'green', 3:'white', 4:'yellow'})
            sage: show(S, xmin=0, xmax=1, ymin=0, ymax=1, aspect_ratio=1, axes=false)

            sage: S=V.plot(cell_colors=['red','blue','red','white', 'white'])
            sage: show(S, xmin=0, xmax=1, ymin=0, ymax=1, aspect_ratio=1, axes=false)

            sage: S=V.plot(cell_colors='something else')
            Traceback (most recent call last):
            ...
            AssertionError: 'cell_colors' must be a list or a dictionary


        Trying to plot a Voronoi diagram of dimension other than 2 gives an
        error::

            sage: VoronoiDiagram([[1, 2, 3], [6, 5, 4]]).plot()
            Traceback (most recent call last):
            ...
            NotImplementedError: Plotting of 3-dimensional Voronoi diagrams not
            implemented
        """

        if self.ambient_dim() == 2:
            S = line([])

            if cell_colors is None:
                from random import shuffle
                cell_colors = rainbow(self._n)
                shuffle(cell_colors)
            else:
                if not (isinstance(cell_colors, list) or (isinstance(cell_colors, dict))):
                    raise AssertionError("'cell_colors' must be a list or a dictionary")
            for i, p in enumerate(self._P):
                col = cell_colors[i]
                S += (self.regions()[p]).render_solid(color=col, zorder=1)
                S += point(p, color=col, pointsize=10, zorder=3)
                S += point(p, color='black', pointsize=20, zorder=2)
            return plot(S, **kwds)
        raise NotImplementedError('Plotting of ' + str(self.ambient_dim()) +
                                  '-dimensional Voronoi diagrams not' +
                                  ' implemented')