Plots Edges
(For LaTeX drawings of graphs, see thegraph_latex
module.)
All graphs have an associated Sage graphics object, which you can display:
If you create a graph in Sage using the Graph
command, then plot that graph,the positioning of nodes is determined using the spring-layout algorithm. Forthe special graph constructors, which you get using graphs.[tab]
, thepositions are preset. For example, consider the Petersen graph with default nodepositioning vs. the Petersen graph constructed by this database:
Plot histogram with specific color, edge color and line width import numpy as np import matplotlib.pyplot as plt expdata = np.array (12, 15, 13, 20, 19, 20, 11, 19, 11, 12, 19, 13. 2 days ago Plot edges conditional on speed limit in python's OSMnx - Stack Overflow Plot edges conditional on speed limit in python's OSMnx 0 I need to plot edges conditional on the speedkph values such that edges with speedkph A are color X and edges with speedkph. Line and volume plots can be added the same way I added a surface plot in the previous example, by right-clicking the Results node or using the ribbon. Next, I’ll add a new 3D plot group with a line plot. Using the View node again, this time to hide the edges of the channel. I have plotted only the edges of the heat sink. This plot will show.
For all the constructors in this database (except some random graphs), theposition dictionary is filled in, instead of using the spring-layout algorithm.
Plot options
Here is the list of options accepted byplot()
and the constructor ofGraphPlot
. Those two functions also accept all options ofsage.plot.graphics.Graphics.show()
.
| A layout algorithm – one of : “acyclic”, “circular” (plots the graph with vertices evenly distributed on a circle), “ranked”, “graphviz”, “planar”, “spring” (traditional spring layout, using the graph’s current positions as initial positions), or “tree” (the tree will be plotted in levels, depending on minimum distance for the root). |
| The number of times to execute the spring layout algorithm. |
| A dictionary mapping heights to the list of vertices at this height. |
| Use spring layout to finalize the current layout. |
| A vertex designation for drawing trees. A vertex of the tree to be used as the root for the |
| An iterable specifying which vertices to use as roots for the |
| The direction of tree branches – ‘up’, ‘down’, ‘left’ or ‘right’. |
| Whether or not to save the computed position for the graph. |
| The dimension of the layout – 2 or 3. |
| Which graphviz layout program to use – one of “circo”, “dot”, “fdp”, “neato”, or “twopi”. |
| Whether to do the spring layout by connected component – a boolean. |
| The position dictionary of vertices |
| Whether or not to draw vertex labels. |
| Default color for vertices not listed in vertex_colors dictionary. |
| Dictionary of vertex coloring : each key is a color recognizable by matplotlib, and each corresponding entry is a list of vertices. |
| The size to draw the vertices. |
| The shape to draw the vertices. Currently unavailable for Multi-edged DiGraphs. |
| Whether or not to draw edge labels. |
| The linestyle of the edges. It should be one of “solid”, “dashed”, “dotted”, dashdot”, or “-“, “–”, “:”, “-.”, respectively. |
| The thickness of the edges. |
| The default color for edges not listed in edge_colors. |
| a dictionary specifying edge colors: each key is a color recognized by matplotlib, and each entry is a list of edges. |
| Whether to color the edges according to their labels. This also accepts a function or dictionary mapping labels to colors. |
| A partition of the vertex set. If specified, plot will show each cell in a different color. vertex_colors takes precedence. |
| The radius of the smallest loop. |
| The distance between multiedges. |
| The max distance range to allow multiedges. |
| Whether to display the vertices in talk mode (larger and white). |
| Whether or not to draw a frame around the graph. |
| The color of the background of the edge labels |
Default options
This module defines two dictionaries containing default options for theplot()
andshow()
methods. These twodictionaries are sage.graphs.graph_plot.DEFAULT_PLOT_OPTIONS
andsage.graphs.graph_plot.DEFAULT_SHOW_OPTIONS
, respectively.
Obviously, these values are overruled when arguments are given explicitly.
Here is how to define the default size of a graph drawing to be [6,6]
. Thefirst two calls to show()
use thisoption, while the third does not (a value for figsize
is explicitly given):
We can now reset the default to its initial value, and now display graphs aspreviously:
Note
While
DEFAULT_PLOT_OPTIONS
affects bothG.show()
andG.plot()
,settings fromDEFAULT_SHOW_OPTIONS
only affectsG.show()
.In order to define a default value permanently, you can add a couple oflines to Sage’s startup scripts. Example:
Index of methods and functions
Set the position plotting parameters for this GraphPlot. |
Set the vertex plotting parameters for this GraphPlot. |
Set the edge (or arrow) plotting parameters for the GraphPlot object. |
Show the (Di)Graph associated with this GraphPlot object. |
Return a graphics object representing the (di)graph. |
Compute a nice layout of a tree. |
sage.graphs.graph_plot.
GraphPlot
(graph, options)¶Bases: sage.structure.sage_object.SageObject
Return a GraphPlot
object, which stores all the parameters neededfor plotting (Di)Graphs.
A GraphPlot
has a plot and show function, as well as some functionsto set parameters for vertices and edges. This constructor assumesdefault options are set. Defaults are shown in the example below.
EXAMPLES:
Plots Edges Meaning
layout_tree
(root, orientation)¶Compute a nice layout of a tree.
INPUT:
root
– the root vertex.orientation
– whether to place the root at the top or at thebottom:orientation='down'
– children are placed below their parentorientation='top'
– children are placed above their parent
EXAMPLES:
Plots Edges Pictures
plot
(**kwds)¶Return a graphics object representing the (di)graph.
INPUT:
The options accepted by this method are to be found in the documentationof the sage.graphs.graph_plot
module, and theshow()
method.
Note
See themodule'sdocumentation
forinformation on default values of this method.
We can specify some pretty precise plotting of familiar graphs:
Here are some more common graphs with typical options:
The options for plotting also work with directed graphs:
This example shows off the coloring of edges:
With the partition
option, we can separate out same-color groupsof vertices:
Loops are also plotted correctly:
More options:
We can plot multiple graphs:
The tree layout is also useful:
More examples:
The edge_style
option may be provided in the short format too:
set_edges
(**edge_options)¶Set the edge (or arrow) plotting parameters for the GraphPlot
object.
This function is called by the constructor but can also be called tomake updates to the vertex options of an existing GraphPlot
object.Note that the changes are cumulative.
EXAMPLES:
set_pos
()¶Set the position plotting parameters for this GraphPlot.
Plots Edges Shapes
EXAMPLES:
This function is called implicitly by the code below:
The following illustrates the format of a position dictionary, but dueto numerical noise we do not check the values themselves:
set_vertices
(**vertex_options)¶Set the vertex plotting parameters for this GraphPlot
.
This function is called by the constructor but can also be called tomake updates to the vertex options of an existing GraphPlot
object.Note that the changes are cumulative.
EXAMPLES:
show
(**kwds)¶Pilots Edges
Show the (Di)Graph associated with this GraphPlot
object.
INPUT:
This method accepts all parameters ofsage.plot.graphics.Graphics.show()
.
Plots Edges Definition
Note
See
themodule'sdocumentation
forinformation on default values of this method.Any options not used by plot will be passed on to the
show()
method.
Plots Edges
EXAMPLES: