Function Repository Resource:

GraphFunctionPlot

Source Notebook

Plot the values of a function at the vertices of a graph

Contributed by: Stephen Wolfram and Jan Mangaldan

ResourceFunction["GraphFunctionPlot"][g,a]

plots the values of the Association a at the vertices of the graph g.

ResourceFunction["GraphFunctionPlot"][g,a,fun]

uses the function fun to make the plot.

Details and Options

Possible values of fun include GraphPlot and GraphPlot3D.
ResourceFunction["GraphFunctionPlot"] takes the same options as the plotting function fun, with the following additions and changes:
ColorFunctionAutomaticfunction to use for coloring the vertices
ColorFunctionScalingTruewhether to scale the argument to ColorFunction
PlotRangeAutomaticthe range of values to include
ColorFunction is supplied with a single argument, corresponding to the associated values for the vertices.
For edges, the color is determined by applying the color function to the mean of the values corresponding to the included vertices.
The default ColorFunction of Automatic uses ColorData["RedBlueTones"].

Examples

Basic Examples (1) 

A graph colored by values:

In[1]:=
ResourceFunction["GraphFunctionPlot"][
 Graph[{1 -> 2, 2 -> 3, 3 -> 1}], <|1 -> 0, 2 -> 0.5, 3 -> 1|>, VertexSize -> 0.2]
Out[1]=

Scope (2) 

Visualize a path graph:

In[2]:=
ResourceFunction["GraphFunctionPlot"][PathGraph[Range[10]], Association@Thread[Range[10] -> Range[10]]]
Out[2]=

Use GraphPlot3D as the plotting function:

In[3]:=
ResourceFunction["GraphFunctionPlot"][
 Graph[{1 -> 2, 2 -> 3, 3 -> 1}], <|1 -> 0, 2 -> 0.5, 3 -> 1|>, GraphPlot3D]
Out[3]=

Options (4) 

ColorFunction (2) 

Use GrayLevel for coloring:

In[4]:=
ResourceFunction["GraphFunctionPlot"][
 Graph[{1 -> 2, 2 -> 3, 3 -> 1}], <|1 -> 0, 2 -> 0.5, 3 -> 1|>, ColorFunction -> GrayLevel]
Out[4]=

Use a color gradient:

In[5]:=
ResourceFunction["GraphFunctionPlot"][
 Graph[{1 -> 2, 2 -> 3, 3 -> 1}], <|1 -> 0, 2 -> 0.5, 3 -> 1|>, ColorFunction -> "LightTemperatureMap"]
Out[5]=

ColorFunctionScaling (1) 

Color the graph with and without scaling:

In[6]:=
ResourceFunction["GraphFunctionPlot"][
 Graph[{1 -> 2, 2 -> 3, 3 -> 1, 1 -> 4, 4 -> 5, 5 -> 1}], <|1 -> 0, 2 -> 0.5, 3 -> 1, 4 -> 1.5, 5 -> 2|>, ColorFunction -> Hue, ColorFunctionScaling -> True]
Out[6]=
In[7]:=
ResourceFunction["GraphFunctionPlot"][
 Graph[{1 -> 2, 2 -> 3, 3 -> 1, 1 -> 4, 4 -> 5, 5 -> 1}], <|1 -> 0, 2 -> 0.5, 3 -> 1, 4 -> 1.5, 5 -> 2|>, ColorFunction -> Hue, ColorFunctionScaling -> False]
Out[7]=

PlotRange (1) 

Use a different range:

In[8]:=
ResourceFunction["GraphFunctionPlot"][
 Graph[{1 -> 2, 2 -> 3, 3 -> 1}], <|1 -> 0, 2 -> 0.5, 3 -> 1|>, GraphPlot, VertexLabels -> Automatic, PlotRange -> {-1, 1}]
Out[8]=

Version History

  • 1.0.0 – 17 March 2020

Related Resources

License Information