# Drawing properties (newbie question)

**URL:** <https://forum.skewed.de/t/drawing-properties-newbie-question/124>\
**Category:** graph-tool\
**Tags:** imported\
**Created:** [June 15, 2011, 8:39pm UTC](https://forum.skewed.de/t/drawing-properties-newbie-question/124 "2011-06-15T20:39:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustav](https://forum.skewed.de/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@Gustav](https://forum.skewed.de/u/Gustav)\
**Post date:** [June 15, 2011, 8:39pm UTC](https://forum.skewed.de/t/drawing-properties-newbie-question/124/1 "2011-06-15T20:39:21Z")

</div>

Hello,

I'm a newcomer to Python and I don't understand the way I could get drawn  
some properties for edges or vertices.

The documentation says:

vprops : dict (default: {})

&nbsp;&nbsp;&nbsp;&nbsp;Additional vertex properties, as a dictionary. The keys are the property  
names, and the values must be convertible to string, or vertex property  
maps, with values convertible to strings.

But I guess that I'm missing something with Python as I only get drawn a  
text description of the object. Foe example:

If I try a sentence like

graph\_draw(g, eprops={"label": g.edge\_properties}, output="two-nodes2.png")

it draws obviously the label for that object which is:

{'occ': &lt;PropertyMap object with key type 'Edge' and value type  
'int32\_t', for Graph 0x2f6dcd0, at 0x2f6de10&gt;}

But I don't understand which parameter I should pass to graph\_draw in order  
to get the desired outcome.

Could you provide a mini-example of drawing a small graph with properties on  
edges/vertices? This could also be added to the Quick tutorial.

Thank you in advance peers.

Regards.

---

<div class="post-metadata">

**Author:** ![tiago](https://forum.skewed.de/user_avatar/forum.skewed.de/tiago/32/3_2.png) [@tiago](https://forum.skewed.de/u/tiago)\
**Post date:** [June 16, 2011, 12:50pm UTC](https://forum.skewed.de/t/drawing-properties-newbie-question/124/2 "2011-06-16T12:50:14Z")

</div>

Hi Gustav,

> If I try a sentence like
> 
> graph\_draw(g, eprops={"label": g.edge\_properties}, output="two-nodes2.png")
> 
> it draws obviously the label for that object which is:
> 
> {'occ': &lt;PropertyMap object with key type 'Edge' and value type  
> 'int32\_t', for Graph 0x2f6dcd0, at 0x2f6de10&gt;}
> 
> But I don't understand which parameter I should pass to graph\_draw in order  
> to get the desired outcome.

The attribute g.edge\_properties is a dictionary of internal property  
maps. What you want to so is to pass some property map in isolation, not  
all of them. What you want to pass depends of course of what you want to  
do, which is not very clear to me.

Suppose, for instance, you have a property map which has numeric value  
for each edge, which is called "edge\_prop", which is created as such:

&nbsp;&nbsp;&nbsp;&nbsp;edge\_prop = g.new\_edge\_property("double")  
&nbsp;&nbsp;&nbsp;&nbsp;for e in g.edges():  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edge\_prop[e] = random() # fill with random values

If you want to draw a label on top of the edges with these values you  
would do:

&nbsp;&nbsp;&nbsp;graph\_draw(g, eprops={"label": edge\_prop})

If, instead you want it to represent the length of the edge, you would do  
something like:

&nbsp;&nbsp;&nbsp;graph\_draw(g, eprops={"len": edge\_prop})

Take a look at [Attributes | Graphviz](http://www.graphviz.org/doc/info/attrs.html) for all  
possible properties one can set.

Note that for vertex and edge color, as well as size, graph\_draw()  
provides direct parameters, so one does not need to pass anything to  
eprops or vprops.

Cheers,  
Tiago

---

<div class="post-metadata">

**Author:** ![Gustav](https://forum.skewed.de/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@Gustav](https://forum.skewed.de/u/Gustav)\
**Post date:** [June 16, 2011, 2:10pm UTC](https://forum.skewed.de/t/drawing-properties-newbie-question/124/3 "2011-06-16T14:10:18Z")

</div>

Hello,

Thank you Tiago.

I think I got it now. I was misunderstanding those "label"/"len" parametres  
as something within the dictionary when in fact they are refering to  
properties in GraphViz.

I'll make some tests and if I'll have some doubts yet I'll be back.

Thanks again.

Regards.
