Plots Edges

Plots Edges Average ratng: 3,7/5 7103 reviews

(For LaTeX drawings of graphs, see thegraph_latexmodule.)

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().

layout

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).

iterations

The number of times to execute the spring layout algorithm.

heights

A dictionary mapping heights to the list of vertices at this height.

spring

Use spring layout to finalize the current layout.

tree_root

A vertex designation for drawing trees. A vertex of the tree to be used as the root for the layout='tree' option. If no root is specified, then one is chosen close to the center of the tree. Ignored unless layout='tree'.

forest_roots

An iterable specifying which vertices to use as roots for the layout='forest' option. If no root is specified for a tree, then one is chosen close to the center of the tree. Ignored unless layout='forest'.

tree_orientation

The direction of tree branches – ‘up’, ‘down’, ‘left’ or ‘right’.

save_pos

Whether or not to save the computed position for the graph.

dim

The dimension of the layout – 2 or 3.

prog

Which graphviz layout program to use – one of “circo”, “dot”, “fdp”, “neato”, or “twopi”.

by_component

Whether to do the spring layout by connected component – a boolean.

pos

The position dictionary of vertices

vertex_labels

Whether or not to draw vertex labels.

vertex_color

Default color for vertices not listed in vertex_colors dictionary.

vertex_colors

Dictionary of vertex coloring : each key is a color recognizable by matplotlib, and each corresponding entry is a list of vertices.

vertex_size

The size to draw the vertices.

vertex_shape

The shape to draw the vertices. Currently unavailable for Multi-edged DiGraphs.

edge_labels

Whether or not to draw edge labels.

edge_style

The linestyle of the edges. It should be one of “solid”, “dashed”, “dotted”, dashdot”, or “-“, “–”, “:”, “-.”, respectively.

edge_thickness

The thickness of the edges.

edge_color

The default color for edges not listed in edge_colors.

edge_colors

a dictionary specifying edge colors: each key is a color recognized by matplotlib, and each entry is a list of edges.

color_by_label

Whether to color the edges according to their labels. This also accepts a function or dictionary mapping labels to colors.

partition

A partition of the vertex set. If specified, plot will show each cell in a different color. vertex_colors takes precedence.

loop_size

The radius of the smallest loop.

dist

The distance between multiedges.

max_dist

The max distance range to allow multiedges.

talk

Whether to display the vertices in talk mode (larger and white).

graph_border

Whether or not to draw a frame around the graph.

edge_labels_background

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 both G.show() and G.plot(),settings from DEFAULT_SHOW_OPTIONS only affects G.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.

class 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 parent

    • orientation='top' – children are placed above their parent

Plots Edges

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:

Definition

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 GraphPlotobject.

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

Plots 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 theshow() method.

Plots Edges

EXAMPLES: