This library uses the LaTeX package pgf/tikz to produce graphs. It outputs SVG images to the notebook.
using Pkg
Pkg.add("TikzGraphs")
In addition, you will need to install the following dependencies if you do not already have them on your system.
sudo apt-get install pdf2svg
. On Windows, you can download the binaries from http://www.cityinthesky.co.uk/opensource/pdf2svg/. Be sure to add pdf2svg to your path (and restart).Once these things are installed, you should be able to run the following:
using TikzGraphs
using TikzGraphs
using Graphs
g = DiGraph(4)
add_edge!(g, 1, 2)
add_edge!(g, 2, 3)
TikzGraphs.plot(g)
add_edge!(g, 3, 4)
add_edge!(g, 1, 4)
TikzGraphs.plot(g)
You can save your graphs to PDF, SVG, and TEX.
t = TikzGraphs.plot(g)
using TikzPictures # this is required for saving
TikzPictures.save(PDF("graph"), t)
TikzPictures.save(SVG("graph"), t)
TikzPictures.save(TEX("graph"), t)
You can also specify the node labels.
TikzGraphs.plot(g, ["A", "B", "C", "D"])
You can even use unicode.
TikzGraphs.plot(g, ["α", "β", "γ", "δ"])
You can also have latex labels.
using LaTeXStrings
TikzGraphs.plot(g, [L"\int_0^\infty f(x) dx", L"\sqrt{2}", L"x^2", L"\frac{1}{2}"])
You can have repeated labels.
TikzGraphs.plot(g, ["α", "β", "γ", "α"])
You can specify the style for the nodes.
TikzGraphs.plot(g, ["α", "β", "γ", "α"], node_style="draw, rounded corners, fill=blue!10")
You can override the styles of selected nodes using a dictionary.
TikzGraphs.plot(g, ["α", "β", "γ", "α"], node_style="draw, rounded corners, fill=blue!10", node_styles=Dict(1=>"fill=green!10",3=>"fill=yellow!10"))
You can set edge labels using a dictionary.
TikzGraphs.plot(g, ["α", "β", "γ", "α"], edge_labels=Dict((1,2)=>"x", (1,4)=>"y"))
You can set the style for the edges.
TikzGraphs.plot(g, ["α", "β", "γ", "α"], edge_labels=Dict((1,2)=>"x", (1,4)=>"y"), edge_style="green")
You can overide the style for specific edges as specified by a dictionary.
TikzGraphs.plot(g, edge_labels=Dict((1,2)=>"x", (1,4)=>"y"), edge_style="green", edge_styles=Dict((1,2)=>"blue"))
You can draw self-loop edges by specifying the edge style.
loop_g = deepcopy(g)
add_edge!(loop_g, (4,4))
TikzGraphs.plot(loop_g, edge_labels=Dict((1,2)=>"x", (1,4)=>"y", (4,4)=>"loop"), edge_styles=Dict((4,4)=>"loop right"))
You can use different layouts (currently just Layered [default], Spring, and SimpleNecklace are supported).
TikzGraphs.plot(g, Layouts.Layered())
TikzGraphs.plot(g, Layouts.Spring())
You can set the random seed for the Spring layout.
TikzGraphs.plot(g, Layouts.Spring(randomSeed=52))
TikzGraphs.plot(g, Layouts.SimpleNecklace())
TikzGraphs.plot(g, node_style="draw", options="scale=2, font=\\huge\\sf")
TikzGraphs.plot(g, node_style="draw", graph_options="nodes={draw,circle}")
Gradually, more functionality from pgf/tikz will be migrated into this package.