Exemple #1
0
def to_graphics_array(graph_list, **kwds):
    """
    Draw all graphs in a graphics array

    INPUT:

    -  ``graph_list`` - a list of Sage graphs

    GRAPH PLOTTING:

    Defaults to circular layout for graphs. This allows
    for a nicer display in a small area and takes much less time to
    compute than the spring- layout algorithm for many graphs.

    EXAMPLES::

        sage: glist = []
        sage: for i in range(999):
        ....:     glist.append(graphs.RandomGNP(6,.45))
        sage: garray = graphs_list.to_graphics_array(glist)
        sage: garray.nrows(), garray.ncols()
        (250, 4)

    See the .plot() or .show() documentation for an individual graph
    for options, all of which are available from
    :func:`to_graphics_array`::

        sage: glist = []
        sage: for _ in range(10):
        ....:     glist.append(graphs.RandomLobster(41, .3, .4))
        sage: graphs_list.to_graphics_array(glist, layout='spring', vertex_size=20)
        Graphics Array of size 3 x 4
    """
    from sage.graphs import graph
    plist = []
    for graph_i in graph_list:
        if isinstance(graph_i, graph.GenericGraph):
            pos = graph_i.get_pos()
            if pos is None:
                if 'layout' not in kwds:
                    kwds['layout'] = 'circular'
                if 'vertex_size' not in kwds:
                    kwds['vertex_size'] = 50
                if 'vertex_labels' not in kwds:
                    kwds['vertex_labels'] = False
                kwds['graph_border'] = True
                plist.append(graph_i.plot(**kwds))
            else:
                plist.append(
                    graph_i.plot(pos=pos,
                                 vertex_size=50,
                                 vertex_labels=False,
                                 graph_border=True))
        else:
            raise TypeError('param list must be a list of Sage (di)graphs.')
    from sage.plot.plot import graphics_array
    return graphics_array(plist, ncols=4)
Exemple #2
0
def to_graphics_array(graph_list, **kwds):
    """
    Draw all graphs in a graphics array

    INPUT:

    -  ``graph_list`` - a list of Sage graphs

    GRAPH PLOTTING: 

    Defaults to circular layout for graphs. This allows
    for a nicer display in a small area and takes much less time to
    compute than the spring- layout algorithm for many graphs.

    EXAMPLES::

        sage: glist = []
        sage: for i in range(999):
        ....:     glist.append(graphs.RandomGNP(6,.45))
        sage: garray = graphs_list.to_graphics_array(glist)
        sage: garray.nrows(), garray.ncols()
        (250, 4)

    See the .plot() or .show() documentation for an individual graph
    for options, all of which are available from
    :func:`to_graphics_array`::

        sage: glist = []
        sage: for _ in range(10):
        ...       glist.append(graphs.RandomLobster(41, .3, .4))
        sage: graphs_list.to_graphics_array(glist, layout='spring', vertex_size=20)
        Graphics Array of size 3 x 4
    """
    from sage.graphs import graph
    plist = []
    for i in range(len(graph_list)):
        if isinstance(graph_list[i], graph.GenericGraph):
            pos = graph_list[i].get_pos()
            if pos is None:
                if 'layout' not in kwds:
                    kwds['layout'] = 'circular'
                if 'vertex_size' not in kwds:
                    kwds['vertex_size'] = 50
                if 'vertex_labels' not in kwds:
                    kwds['vertex_labels'] = False
                kwds['graph_border'] = True
                plist.append(graph_list[i].plot(**kwds))
            else:
                plist.append(graph_list[i].plot(pos=pos, vertex_size=50, vertex_labels=False, graph_border=True))
        else:
            raise TypeError('param list must be a list of Sage (di)graphs.')
    from sage.plot.plot import graphics_array
    return graphics_array(plist, ncols=4)
Exemple #3
0
def percolation_graphics_array(range_p, d, m, ncols=3):
    r"""
    EXAMPLES::

        sage: from slabbe.bond_percolation import percolation_graphics_array
        sage: percolation_graphics_array(srange(0.1,1,0.1), d=2, m=5)    # optional long
        sage: P = percolation_graphics_array(srange(0.45,0.55,0.01), d=2, m=5)  # optional long
        sage: P.save('array_p45_p55_m5.png')     # not tested
        sage: P = percolation_graphics_array(srange(0.45,0.55,0.01), d=2, m=10) # optional long
        sage: P.save('array_p45_p55_m10.png')    # not tested
    """
    pointsize=20
    thickness=1
    L = [BondPercolationSample(p,d).plot(m,pointsize=pointsize,thickness=thickness) for p in range_p]
    nrows = (len(range_p)-1) // ncols + 1
    return graphics_array(L, n=nrows, m=ncols)
Exemple #4
0
    def _concatenate_graphics(self):
        """
        Combine multiple graphics objects into one graphics array

        OUTPUT:

        A graphics array.

        EXAMPLES::

            sage: from sage.repl.rich_output.pretty_print import SequencePrettyPrinter
            sage: ga = SequencePrettyPrinter(*[Graphics()]*5)._concatenate_graphics()
            sage: type(ga)
            <class 'sage.plot.multigraphics.GraphicsArray'>
            sage: ga.nrows(), ga.ncols()
            (2, 4)
        """
        from sage.plot.plot import graphics_array
        return graphics_array(self.args, ncols=4, **self.kwds)
Exemple #5
0
    def _concatenate_graphics(self):
        """
        Combine multiple graphics objects into one graphics array

        OUTPUT:

        A graphics array.

        EXAMPLES::

            sage: from sage.repl.rich_output.pretty_print import SequencePrettyPrinter
            sage: ga = SequencePrettyPrinter(*[Graphics()]*5)._concatenate_graphics()
            sage: type(ga)
            <class 'sage.plot.graphics.GraphicsArray'>
            sage: ga.nrows(), ga.ncols()
            (2, 4)
        """
        from sage.plot.plot import graphics_array
        return graphics_array(self.args, ncols=4, **self.kwds)
Exemple #6
0
def percolation_graphics_array(range_p, d, m, ncols=3):
    r"""
    EXAMPLES::

        sage: from slabbe.bond_percolation import percolation_graphics_array
        sage: percolation_graphics_array(srange(0.1,1,0.1), d=2, m=5)    # optional long
        sage: P = percolation_graphics_array(srange(0.45,0.55,0.01), d=2, m=5)  # optional long
        sage: P.save('array_p45_p55_m5.png')     # not tested
        sage: P = percolation_graphics_array(srange(0.45,0.55,0.01), d=2, m=10) # optional long
        sage: P.save('array_p45_p55_m10.png')    # not tested
    """
    pointsize = 20
    thickness = 1
    L = [
        BondPercolationSample(p, d).plot(m,
                                         pointsize=pointsize,
                                         thickness=thickness) for p in range_p
    ]
    nrows = (len(range_p) - 1) // ncols + 1
    return graphics_array(L, n=nrows, m=ncols)
Exemple #7
0
def to_graphics_arrays(list, **kwds):
    """
    Returns a list of Sage graphics arrays containing the graphs in
    list. The maximum number of graphs per array is 20 (5 rows of 4).
    Use this function if there are too many graphs for the show_graphs
    function. The graphics arrays will contain 20 graphs each except
    potentially the last graphics array in the list.
    
    INPUT:
    
    
    -  ``list`` - a list of Sage graphs
    
    
    GRAPH PLOTTING: Defaults to circular layout for graphs. This allows
    for a nicer display in a small area and takes much less time to
    compute than the spring- layout algorithm for many graphs.
    
    EXAMPLES::
    
        sage: glist = []
        sage: for i in range(999):
        ...    glist.append(graphs.RandomGNP(6,.45))
        ...
        sage: garray = graphs_list.to_graphics_arrays(glist)
    
    Display the first graphics array in the list.
    
    ::
    
        sage: garray[0].show()
    
    Display the last graphics array in the list.
    
    ::
    
        sage: garray[len(garray)-1].show()
    
    See the .plot() or .show() documentation for an individual graph
    for options, all of which are available from to_graphics_arrays
    
    ::
    
        sage: glist = []
        sage: for _ in range(10):
        ...       glist.append(graphs.RandomLobster(41, .3, .4))
        sage: w = graphs_list.to_graphics_arrays(glist, layout='spring', vertex_size=20)
        sage: len(w)
        1
        sage: w[0]
    """
    from sage.plot.plot import graphics_array
    from sage.graphs import graph
    plist = []
    g_arrays = []
    for i in range (len(list)):
        if ( isinstance( list[i], graph.GenericGraph ) ):
            pos = list[i].get_pos()
            if ( pos is None ):
                if not kwds.has_key('layout'):
                    kwds['layout'] = 'circular'
                if not kwds.has_key('vertex_size'):
                    kwds['vertex_size'] = 50
                if not kwds.has_key('vertex_labels'):
                    kwds['vertex_labels'] = False
                kwds['graph_border'] = True
                plist.append(list[i].plot(**kwds))
            else: plist.append(list[i].plot(pos=pos, vertex_size=50, vertex_labels=False, graph_border=True))
        else:  raise TypeError, 'Param list must be a list of Sage (di)graphs.'
    
    num_arrays = len(plist)/20
    if ( len(plist)%20 > 0 ): num_arrays += 1
    rows = 5
    cols = 4

    for i in range (num_arrays-1):
        glist = []
        for j in range (rows*cols):
            glist.append(plist[ i*rows*cols + j ])
        ga = graphics_array(glist, rows, cols)
        ga._set_figsize_([8,10])
        g_arrays.append(ga)
    
    last = len(plist)%20
    if ( last == 0 and len(plist) != 0 ): last = 20
    index = (num_arrays-1)*rows*cols
    last_rows = last/cols
    if ( last%cols > 0 ): last_rows += 1
    
    glist = []
    for i in range (last):
        glist.append(plist[ i + index])
    ga = graphics_array(glist, last_rows, cols)
    ga._set_figsize_([8, 2*last_rows])
    g_arrays.append(ga)
    
    return g_arrays
Exemple #8
0
def to_graphics_arrays(list, **kwds):
    """
    Returns a list of Sage graphics arrays containing the graphs in
    list. The maximum number of graphs per array is 20 (5 rows of 4).
    Use this function if there are too many graphs for the show_graphs
    function. The graphics arrays will contain 20 graphs each except
    potentially the last graphics array in the list.

    INPUT:


    -  ``list`` - a list of Sage graphs


    GRAPH PLOTTING: Defaults to circular layout for graphs. This allows
    for a nicer display in a small area and takes much less time to
    compute than the spring- layout algorithm for many graphs.

    EXAMPLES::

        sage: glist = []
        sage: for i in range(999):
        ...    glist.append(graphs.RandomGNP(6,.45))
        ...
        sage: garray = graphs_list.to_graphics_arrays(glist)

    Display the first graphics array in the list.

    ::

        sage: garray[0].show()

    Display the last graphics array in the list.

    ::

        sage: garray[len(garray)-1].show()

    See the .plot() or .show() documentation for an individual graph
    for options, all of which are available from to_graphics_arrays

    ::

        sage: glist = []
        sage: for _ in range(10):
        ...       glist.append(graphs.RandomLobster(41, .3, .4))
        sage: w = graphs_list.to_graphics_arrays(glist, layout='spring', vertex_size=20)
        sage: len(w)
        1
        sage: w[0]
    """
    from sage.plot.plot import graphics_array
    from sage.graphs import graph
    plist = []
    g_arrays = []
    for i in range(len(list)):
        if (isinstance(list[i], graph.GenericGraph)):
            pos = list[i].get_pos()
            if (pos is None):
                if 'layout' not in kwds:
                    kwds['layout'] = 'circular'
                if 'vertex_size' not in kwds:
                    kwds['vertex_size'] = 50
                if 'vertex_labels' not in kwds:
                    kwds['vertex_labels'] = False
                kwds['graph_border'] = True
                plist.append(list[i].plot(**kwds))
            else:
                plist.append(list[i].plot(pos=pos,
                                          vertex_size=50,
                                          vertex_labels=False,
                                          graph_border=True))
        else:
            raise TypeError('Param list must be a list of Sage (di)graphs.')

    num_arrays = len(plist) // 20
    if (len(plist) % 20 > 0): num_arrays += 1
    rows = 5
    cols = 4

    for i in range(num_arrays - 1):
        glist = []
        for j in range(rows * cols):
            glist.append(plist[i * rows * cols + j])
        ga = graphics_array(glist, rows, cols)
        ga._set_figsize_([8, 10])
        g_arrays.append(ga)

    last = len(plist) % 20
    if (last == 0 and len(plist) != 0): last = 20
    index = (num_arrays - 1) * rows * cols
    last_rows = last / cols
    if (last % cols > 0): last_rows += 1

    glist = []
    for i in range(last):
        glist.append(plist[i + index])
    ga = graphics_array(glist, last_rows, cols)
    ga._set_figsize_([8, 2 * last_rows])
    g_arrays.append(ga)

    return g_arrays