Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the width and heigth of the ouput image in Pygraphviz

I am creating a .png file like this:

import pygraphviz as pgv
G = pgv.AGraph()
G.add_nodes("a")
G.add_edge("b", "c")

G.layout()
G.draw("output.png")

How can I set the size of the output image?

like image 904
jbochi Avatar asked Aug 15 '10 21:08

jbochi


1 Answers

You can set the maximum size of your output image, by setting size, which is an attribute of the graph object. E.g.,

digraph "my_graph" {

     graph[ fontname = "Helvetica-Oblique",
            fontsize = 12,
            label = "some label",
            size = "7.75,10.25" ];

     node [ shape = polygon,
            sides = 4 ];
}

In this example, i've set the graph size to 7.75 x 10.25, which is the size you want, to ensure that your graph fits on an 8.5 x 11 inch sheet and also to ensure that it occupies all of the space on that sheet.

like image 86
doug Avatar answered Sep 22 '22 15:09

doug