{ "metadata": { "language": "Julia", "name": "", "signature": "sha256:76db2c5c95005e142473bd0741d7417d5dde2f2e1731cf1a01409abbef8c9a19" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "TikzGraphs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This library uses the LaTeX package [pgf/tikz](http://www.ctan.org/pkg/pgf) to produce graphs. It integrates with IJulia, outputting SVG images to the notebook." ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Installation" ] }, { "cell_type": "code", "collapsed": false, "input": [ "Pkg.add(\"Images\")\n", "Pkg.clone(\"https://github.com/sisl/TikzPictures.jl\")\n", "Pkg.clone(\"https://github.com/sisl/TikzGraphs.jl\")" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition, you will need to install the following dependencies if you do not already have them on your system.\n", "* Pdf2svg. This is required by TikzPictures. On Ubuntu, you can get this by running `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).\n", "* Pgf (version 3.0 or later). Install using your latex package manager (e.g., texlive or miktex).\n", "\n", "Once these things are installed, you should be able to run the following:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "using TikzGraphs" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Examples" ] }, { "cell_type": "code", "collapsed": false, "input": [ "using TikzGraphs\n", "using TikzPictures\n", "using Graphs\n", "g = simple_graph(4)\n", "add_edge!(g, 1, 2)\n", "add_edge!(g, 2, 3)\n", "add_edge!(g, 3, 4)\n", "add_edge!(g, 1, 4)\n", "TikzGraphs.plot(g) # You can just use plot(g) if TikzGraphs was loaded after Graphs" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 2, "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n" ], "text": [ "TikzPicture(\"\\\\graph [layered layout, ] {\\n1 -> 2;\\n2 -> 3;\\n3 -> 4;\\n1 -> 4;\\n};\\n\",\"\",\"\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can save your graphs to PDF, SVG, and TEX." ] }, { "cell_type": "code", "collapsed": false, "input": [ "t = TikzGraphs.plot(g)\n", "save(PDF(\"graph\"), t)\n", "save(SVG(\"graph\"), t)\n", "save(TEX(\"graph\"), t)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also specify the labels." ] }, { "cell_type": "code", "collapsed": false, "input": [ "TikzGraphs.plot(g, [\"A\", \"B\", \"C\", \"D\"])" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 4, "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n" ], "text": [ "TikzPicture(\"\\\\graph [layered layout, ] {\\n\\\"A\\\" -> \\\"B\\\";\\n\\\"B\\\" -> \\\"C\\\";\\n\\\"C\\\" -> \\\"D\\\";\\n\\\"A\\\" -> \\\"D\\\";\\n};\\n\",\"\",\"\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can use different layouts (currently just Layered [default] and Spring are supported)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "TikzGraphs.plot(g, Layouts.Spring())" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 8, "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n" ], "text": [ "TikzPicture(\"\\\\graph [spring layout, random seed = 0] {\\n1 -> 2;\\n2 -> 3;\\n3 -> 4;\\n1 -> 4;\\n};\\n\",\"\",\"\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{force}\",true,true)" ] } ], "prompt_number": 8 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Future Plans" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Gradually, more functionality from pgf/tikz will be migrated into this package. Eventually, this package will support different layout options, annotations, styles, etc." ] } ], "metadata": {} } ] }