# Good programs for drawing graphs ( directed weighted graphs )

Does anyone know of a good program for drawing directed weighted graphs?

• What do you mean by "drawing weighted graphs"? That is, what is the significance of the weights? Edge labels? – Igor Rivin Feb 12 '11 at 14:46
• Question is imprecise: does the OP want a program that will produce an automatically generated pleasing layout of a graph on the screen? Or a program to interactively manipulate a displayed graph? Or a program to create a diagram for inclusion in a published paper when the actual layout is already known? – Gordon Royle Dec 17 '11 at 2:23
• @GordonRoyle Of course, ideally one would like to have a program that would automatically generate a pleasing layout which you can then interactively manipulate and export so you can easily include it in your paper. – Vít Tuček Oct 8 '14 at 9:24
• If you just want small graphs and not auto-layout, I've found that (and it pains me to say it) the drawing tools in Word or Powerpoint give the easiest way to make graphs that include arrows, labels, shaded cells, and sometimes dotted line. All of the diagrams in this paper were made in Powerpoint: faculty.tcu.edu/gfriedman/papers/simp.pdf – Greg Friedman Dec 29 '15 at 22:22

Try Sage - it's open source and can draw weighted directed graphs. For example:

A = random_matrix(ZZ,6, density=0.5)
G = DiGraph(A, format='weighted_adjacency_matrix')  # graph from matrix
H = G.plot(edge_labels=True, graph_border=True)
H.show()             # display on screen
H.save('graph.pdf')  # save plot to vector pdf for inclusion in a paper


To supplement William Stein's useful answer, here is a graph produced by running the code he displays:

• By the way, Sage uses NetworkX, which was mentioned in another answer. – William Stein Feb 12 '11 at 18:43
• You can also use NetworkX directly within Sage to have more control over your plotting options. (Sage's Graph class is a wrapper which hides a lot of functionality and is not compatible with the advanced plotting tools.) – Derrick Stolee Feb 13 '11 at 14:44
• Printing the edge labels onto the edges looks horrendous. Otherwise that would be quite nice. – Loreno Heer Nov 10 '16 at 14:04

Check out PGF/tikZ, which is freely available, and interacts extremely well with TeX and LaTeX.

You can find examples here, examples of graphs here, and a nice manual here.

A nice feature of the examples web page is that you can click on each example to get access to the code, which you can then copy-and-paste into your own LaTeX file, and then modify for your own purposes.

Try Graphviz - it's open source and quite flexible as far as usage is concerned.

http://www.graphviz.org/

It's good at automatic layouts etc, where for example Maple would make a mess of things.

• what I'm missing from graphviz is being able to do more programming (at least, being more flexible in changing the shapes for abstract types of nodes and arrows), and also having complex subgraphs as nodes (but this is solved, though not in a very flexible way). – imz -- Ivan Zakharyaschev Apr 15 '15 at 14:52
• So, as for my wish for programming a "device" like graphviz I seem to have found a solution which combines two ideas mentioned here in the answers: Haskell+graphviz! If we want to program diagrams in Haskell, it's not necessary to use diagrams library (not that it's not nice). There is a graphviz library, which allows to program on top of graphviz in different styles, say: * using a graph type; * in a graphviz monad which closely follows the way you write graphviz files -- mathoverflow.net/a/203099/13991 – imz -- Ivan Zakharyaschev Apr 16 '15 at 15:13

I love TikZ. It is a very sophisticated LaTeX package from the same author who wrote Beamer. It takes a bit of getting used to, but once you have your collection of examples, it is extremely efficient and produces very clean-looking and portable graphics. See www.hairer.org/Archive.zip for a few examples.

Mathematica is quite good these days and exports in a bazillion formats.

You could write a Haskell program to generate your diagrams. See projects.haskell.org/diagrams.

a directed graph example

Better yet, why has no one mentioned Evan Wallace's webapp? It generates tikz for you.... cool!

(Now that I read your comments, I see you want some automation... Anyway, as an answer to the original question, i think Evan's app should be mentioned.)

• The disadvantage of that example from Haskell diagrams compared, say, to graphviz is that you must do manual placing of the nodes in Haskell diagrams, whereas graphviz arranges them automatically, just given the structure. But what I'm missing from graphviz is being able to do more programming (at least, being more flexible in changing the shapes for abstract types of nodes and arrows), and also having complex subgraphs as nodes (but this is solved, though not in a very flexible way). – imz -- Ivan Zakharyaschev Apr 15 '15 at 14:52
• So, as for my wish for programming a "device" like graphviz I seem to have found a solution which combines two ideas mentioned here in the answers: Haskell+graphviz! If we want to program diagrams in Haskell, it's not necessary to use diagrams library (not that it's not nice). There is a graphviz library, which allows to program on top of graphviz in different styles, say: * using a graph type; * in a graphviz monad which closely follows the way you write graphviz files -- mathoverflow.net/a/203099/13991 – imz -- Ivan Zakharyaschev Apr 16 '15 at 15:13
• TIL (via rpglover64) "about another point in the design space that makes me very happy. diagrams-graphviz supposedly uses graphviz to layout the graph and diagrams to draw it." – imz -- Ivan Zakharyaschev Dec 20 '15 at 14:26

I am surprised that no one has mentioned IPE. This is a free open source drawing editor which can create extremely complex figures (including graphs). A few colleagues of mine even prepare all their math presentations in IPE.

One thing I've been missing from graphviz is being able to do more programming (at least, being more flexible in changing the shapes for abstract types of nodes and arrows).

Then, I knew there is the powerful diagrams library in Haskell, which however didn't give me straightforwardly the feature of arranging the nodes automatically, as graphviz would do. (Although this must be implementable, of course, but going for a simpler solution, I'd like to use the existing graphviz code.) I'd like to be closer to the simple graphviz usage model.

So, as for my wish for programming a "device" like graphviz I seem to have found a solution which combines two ideas mentioned here in the answers: Haskell+graphviz! If we want to program diagrams in Haskell, it's not necessary to use diagrams library (not that it's not nice). There is a graphviz library, which allows to program on top of graphviz in different styles, say:

• using a graph type;
• in a graphviz monad which closely follows the way you write graphviz files, but is programmable and type-checked! Look at a good example with explanations.
• ... (more?)

A short example of the monadic notation from the documentation:

digraph (Str "G") $do cluster (Int 0)$ do
graphAttrs [style filled, color LightGray]
nodeAttrs [style filled, color White]
"a0" --> "a1"
"a1" --> "a2"
"a2" --> "a3"
graphAttrs [textLabel "process #1"]

cluster (Int 1) $do nodeAttrs [style filled] "b0" --> "b1" "b1" --> "b2" "b2" --> "b3" graphAttrs [textLabel "process #2", color Blue] "start" --> "a0" "start" --> "b0" "a1" --> "b3" "b2" --> "a3" "a3" --> "end" "b3" --> "end" node "start" [shape MDiamond] node "end" [shape MSquare]  Some overview of the relations between the existing Haskell graph packages and graphviz: [Haskell-cafe] Generic Graph Class. ### graphviz Haskell library and other ones In a follow-up to the post mentioning dotgen, the author of graphviz gives some comparison between them (and other similar Haskell libs). I assume his "plans" (about a monadic interface) have been implemented already: Within the next month, I should hopefully finally finish the new version of graphviz. Various improvements include: ... • A Dot graph representation based loosely upon dotgen's monadic interface (with Andy's blessing) but with the various Attributes being used rather than (String, String). I think I'm going to be able to make it such that you can define a graph using the monadic interface that will almost look identical to actual Dot code. ... I would like to stress to people considering using other bindings to Graphviz/Dot (such as dotgen, language-dot, or their own cobbled-together interface): be very careful about quoting, etc. I have spent a lot of time checking how to properly escape different values and ensuring correctness under the hood (i.e. there is no need to pre-escape your Text/String values; graphviz will do that for you when generating the actual Dot code). This, after all, is the point of having existing libraries rather than rolling your own each time. Both points are related. (So, graphviz's monadic iterface is a safer improvement upon dotgen's one.) ### Considering dotgen vs graphviz closer But looking into the examples, I see that dotgen can use "Haskell ids" to identify created nodes, whereas in graphviz's monad (see the example above) one must supply extra strings as the unique ids (by which we refer to the nodes). I like the first approach more ("Haskell ids"). Cf. dotgen (from https://github.com/ku-fpg/dotgen/blob/master/test/DotTest.hs): module Main (main) where import Text.Dot -- data Animation = Start src, box, diamond :: String -> Dot NodeId src label = node$ [ ("shape","none"),("label",label) ]
box     label = node $[ ("shape","box"),("style","rounded"),("label",label) ] diamond label = node$ [("shape","diamond"),("label",label),("fontsize","10")]

main :: IO ()
main = putStrLn $showDot$ do
attribute ("size","40,15")
attribute ("rankdir","LR")
refSpec <- src "S"
tarSpec <- src "T"
same [refSpec,tarSpec]

c1 <- box "S"
c2 <- box "C"
c3 <- box "F"
same [c1,c2,c3]

refSpec .->. c1
tarSpec .->. c2
tarSpec .->. c3

m1 <- box "x"
m2 <- box "y"
ntm <- box "z"

same [m1,m2,ntm]
c1 .->. m1
c2 .->. m2

xilinxSynthesis <- box "x"
c3 .->. xilinxSynthesis

gns <- box "G"
xilinxSynthesis .->. gns

gns .->. ntm

ecs <- sequence
[ diamond "E"
, diamond "E"
, diamond "Eq"
]
same ecs

m1 .->. (ecs !! 0)
m1 .->. (ecs !! 1)
m2 .->. (ecs !! 0)
m2 .->. (ecs !! 2)
ntm .->. (ecs !! 1)
ntm .->. (ecs !! 2)

_ <- sequence [ do evidence <- src "EE"
n .->. evidence
| n <- ecs
]

edge refSpec tarSpec [("label","Engineering\nEffort"),("style","dotted")]

() <- scope $do v1 <- box "Hello" v2 <- box "World" v1 .->. v2 (x,()) <- cluster$
do v1 <- box "Hello"
v2 <- box "World"
v1 .->. v2

--      x .->. m2
-- for hpc
() <- same [x,x]
v <- box "XYZ"
v .->. v
() <- attribute ("rankdir","LR")

let n1 = userNodeId 1
let n2 = userNodeId (-1)

() <- n1 userNode [ ("shape","box")]
n1 .->. n2

_ <- box "XYZ"

_ <- box "(\n\\n)\"(/\\)"

netlistGraph (\ a -> [("label","X" ++ show a)])
(\ a -> [succ a mod 10,pred a mod 10])
[ (n,n) | n <- [0..9] :: [Int] ]

return ()


https://networkx.lanl.gov/trac has a lot of options

Try programming in R for various types of Graphs and Data Analysis. The R Graphs Cookbook is an essential.

You'll find it here.

you can use $newgraph-1.1.3$ for drawing and analysis every graphs. It is very good free software.

Very simple, and easy to use for small graphs: GraphThing. It is in Ubuntu repositories. Here is home page: http://graph.seul.org/ It even computes some simple parameters.

I have used CaGe for some basic planar graphs.

You might try the combinatorial algorithms software Catbox of Alexander Schliep and Wilfried Hochstättler. You can find it via Alexander's homepage.

I've written a program to plot weighted directed graphs with large number of nodes/links. It is called QDirWeiGraph and you can find it on my page : http://fdeloche.github.io/qdirweigraph.html

It works with Qt but I will add binaries that won't need to install Qt.

Inkscape is good too! It will most likely not do it automatically, but in exchange it's one of the most flexible programs out there.

Gephi is pretty user-friendly and has good data-visualization features, they describe it as "like Photoshop but for graph data".

Visual Studio has a powerful Directed Graph document (dgml) creator and viewer. It is highly configurable with styles / legend etc. but if you want to generate graphs from a data model it is quite good but there is a bit of a learning curve. I believe (don't quote me on this) that the free versions of Visual Studio do have support for it.

Disclaimer: I work on features for Visual Studio close to this;

Paul Gastin (LSV, Cachan), developed a package named GasTeX in order to simplify graphs and automata designing in TeX.

Further informations, documentation and CTAN links on http://www.lsv.ens-cachan.fr/~gastin/gastex/

Hope it will be of any use.

GrafEq is light yet usable, it specializes on drawing 'doggy' ones with the lines become really dense. And it's totally free.

• Do you mean "dodgy"? I hope you mean "doggy", and perhaps you can explain the similarity to dogs. – Ben McKay Dec 26 '17 at 10:08

Rather recently (r2015b) MATLAB has added a decent suite of basic algorithms and visualization capabilities for graphs that readily handles weights and directed arcs.

Ross Kirsling's D3.js-based Directed Graph Editor is a simple and convenient point-and-click online graph editor. It doesn't include weighted edges, but it probably wouldn't be difficult to add that capability if you're willing to learn D3.js. (Learning D3.js's weird conceptual model is not necessarily a trivial project, even for experienced programmers). Kirsling's graph editor is not very smart about layout (although that might be fixable), is not designed to load data (although that's easy to add in D3.js), and it lacks other fancy features that some of the tools listed here include. However, it's right there online, and it might be one all needs for some purposes. Kirsling's graph editor is part of his Modal Logic Playground.

Ben Guo's Force Directed Graph Editor, also in D3.js, is a similar tool. The graphs aren't directed, but this tool is better at layout.

EDIT:

(1) Searching on various combinations of "D3" with "directed graph" and "edit" brings up a few more options.

(2) On an iPad interation with D3.js programs sometimes doesn't work well--at least in Safari. The programs mentioned above work fine on a computer, but I couldn't interact fully with them in iOS.

However, for iOS users, Instaviz is a great little app. Although there are many features it doesn't have that I wish it had (I think it's still being developed), what it does do it does very well and pretty easily.

What about https://www.draw.io/ . Easy to use and powerful

• Are you sure this is an answer? – András Bátkai Nov 10 '16 at 12:59