SVG output

1,102 views
Skip to first unread message

DanYamins

unread,
Oct 1, 2008, 10:04:00 PM10/1/08
to pygraphviz-discuss
When I use the draw method to output a graph image in svg format, e.g.
by issuing the command'

G.draw(path = outputpath, format='svg')

I get somewhat strange results -- my graph has long labels, and the
node ellipses are not large enough to accomodate them. And, the
positioning of the nodes is much too crowded.

I'm using pygraphviz on Mac OSX and when I view the dot source of this
same graph in the OSX Graphviz viewer (from pixelglow), and choose to
"export to SVG", the results are much bette. The svg is layed out
properly, with large enough node ellipses and the proper spacing.
Are there some options in the pygraphviz version that I can change to
get results more like these?

Aric Hagberg

unread,
Oct 1, 2008, 11:47:47 PM10/1/08
to pygraphvi...@googlegroups.com

Could it be that you are using two different versions of
Graphviz? (One with pygraphviz and one with pixelglow).
Or maybe pixelglow sets some different defaults from the
basic graphviz defaults?

You can set all of the Graphviz options with pygraphviz.
See
https://networkx.lanl.gov/browser/pygraphviz/trunk/doc/examples/attributes.py
for some examples.

Aric

DanYamins

unread,
Oct 3, 2008, 1:47:35 PM10/3/08
to pygraphviz-discuss
My situation is that:

1) I have a .dot file Graph.dot created by writing out a
pygraphviz "agraph" object, using the .to_string() method.

Then, I have two options. I can:

2a) Convert this .dot file to an .svg file by loading it up and
drawing it out, e.g. by running:


AGragph('Graph.dot').draw('Graph.svg',format='svg',prog='dot')

or

2b) Open the .dot in pixel glow's Graphviz GUI, and then choose
to Export to svg format.

Option 2a) produces poor output -- the node-ellipses are sized
properly to the label of the node, and therefore all the nodes are
bunched together improperly. Option 2b) does not have these
problems.


I've done some more experimenting and it seems like the problem has
something to do with the setting of the "fixedsize" attribute of
the .dot nodes. The 'fixedsize' attribute is such that, if true, the
node size is specified by the values of the width and height
attributes only and is not expanded to contain the text label. The
default value of the fixedsize attribute if "false", so that nodes
_are_ supposed to be expanded to the label size.

The results that I'm getting from using the .draw method to
produce .svg files appears to somehow be setting the 'fixedsize' to
'true'. This is true even when I explicitly set "fixedsize = false"
for all the nodes before drawing the graph. It seems like this
something about the .draw method, not the .dot file. ??


Thanks,
Dan
> Seehttps://networkx.lanl.gov/browser/pygraphviz/trunk/doc/examples/attri...
> for some examples.
>
> Aric

Aric Hagberg

unread,
Oct 3, 2008, 3:49:21 PM10/3/08
to pygraphvi...@googlegroups.com

The draw() method doesn't change any of the default layout options.
Can you try this code and see what you get?

from pygraphviz import *
A=AGraph()
# A.node_attr['fixedsize']='true'
A.add_edge(4,"very long node name")
print A.string() # print dot file to standard output
A.write('test.dot')
# draw below should be the same as same as "dot -Tsvg test.dot >test.svg"
A.draw('test.svg',prog='dot')

FYI: setting fixedsize=true produces an error on my machine
of "size to small for label".

I'm using
dot - Graphviz version 2.16 (Fri Feb 8 12:52:03 UTC 2008)

Aric

Dan Yamins

unread,
Oct 3, 2008, 4:11:26 PM10/3/08
to pygraphvi...@googlegroups.com



The draw() method doesn't change any of the default layout options.
Can you try this code and see what you get?

from pygraphviz import *
A=AGraph()
# A.node_attr['fixedsize']='true'
A.add_edge(4,"very long node name")
print A.string() # print dot file to standard output
A.write('test.dot')


Got the same result, e.g. the node with label "very long node name" has the same (apparently fixed) size as the node with the label "4", so that the label is cut off and the nodes improperly placed.    

What does it look like on your machine?



> # draw below should be the same as same as "dot -Tsvg test.dot >test.svg"
> A.draw('test.svg',prog='dot')


Yeah, I figured this out -- in fact, the same problem happens when I call it via dot.  So it's not a problem with pygraphviz, so much as a problem with dot.   In fact, it's instructive to try this: 

  dot -Tdot test.dot > test2.dot

Now open and compare test.dot and test2.dot in a text editor.  At least with the version of dot that I'm using, widths have been added to the nodes in test2.dot, and both nodes have the same width (.75) even though the labels are different lengths.

If you happen to have pixelglow's version available to you, try opening test.dot in it and then export it to a new file, with format "dot, attributed".   Then open _that_ .dot file in a text editor and you'll see that the node widths have been appropriately sized to the lengths of the labels.
When you convert this .dot file to an .svg file (either by exporting in pixelglow's graphviz, _or_ by opening it as a data object in pygraphviz and then drawing it out, _or_ by using 'dot -Tsvg ...' at the command line), the result is correct.

So, ultimately, something is wrong with my version of dot, I seems to me.  Does yours do the same thing?

 

FYI: setting fixedsize=true produces an error on my machine
of "size to small for label".


Same here.

Thanks,
Dan


Aric Hagberg

unread,
Oct 3, 2008, 4:29:57 PM10/3/08
to pygraphvi...@googlegroups.com
On Fri, Oct 03, 2008 at 04:11:26PM -0400, Dan Yamins wrote:
>
> What does it look like on your machine?

My output looks correct. The node oval entirely encloses the label.

> So, ultimately, something is wrong with my version of dot, I seems to me.
> Does yours do the same thing?

Mine works fine. So maybe you need an updated version of graphviz?

Aric

Dan Yamins

unread,
Oct 3, 2008, 9:00:03 PM10/3/08
to pygraphvi...@googlegroups.com


Mine works fine.  So maybe you need an updated version of graphviz?

Yes, I did this, works now.

Thanks
Dan

Reply all
Reply to author
Forward
0 new messages