Drawing Multigraphs

2,130 views
Skip to first unread message

Nima Mohammadi

unread,
Jun 1, 2010, 8:29:42 AM6/1/10
to networkx-discuss
Hi there,
Is it possible to draw an (undirected) multigraph using NetworkX?
I need to write a program that finds an Eulerian circuit in a graph
(which might obviously be a multigraph). As the output of the program,
I should draw the graph and print out the solution.
Any help would be appreciated :)

* I've used the Fleury algorithm to solve the problem.
--
Yours sincerely,
Nima Mohammadi

Aric Hagberg

unread,
Jun 1, 2010, 8:43:02 AM6/1/10
to networkx...@googlegroups.com

The Matplotlib drawing supported with NetworkX (the draw* functions)
don't show multiple edges. So the best option at this point for
a drawing is to pass the data to another graph drawing package.
I'm not sure what the best one is for handling multigraphs.

Aric

ps. If you are interested in contributing the Fleury algorithm to NetworkX
we can help get it documented, tested, and included.

Nima

unread,
Jun 5, 2010, 12:25:46 PM6/5/10
to networkx...@googlegroups.com

2010/6/1 Aric Hagberg <ahag...@gmail.com>

On Tue, Jun 1, 2010 at 6:29 AM, Nima Mohammadi <nima...@gmail.com> wrote:
ps.  If you are interested in contributing the Fleury algorithm to NetworkX
we can help get it documented, tested, and included.


Even though I didn't need directed graphs in my project, I've added the needed code, so you can put it in the NetworkX library.
The .py file (containing two functions is_eulerian() and eulerian_circuit()) is attached to the mail.
euler.py

Nima

unread,
Jun 5, 2010, 2:14:46 PM6/5/10
to networkx...@googlegroups.com
There is a problem when I give a directed graph to the function.
I'm working on it.

Nima

unread,
Jun 5, 2010, 3:48:58 PM6/5/10
to networkx...@googlegroups.com
I've almost fixed the problem, but there's still something I can't figure out:

>>> G = networkx.MultiDiGraph({0:[1], 1:[2, 2], 2:[1, 0]})
>>> G.edges()
[(0, 1), (1, 2), (1, 2), (2, 0), (2, 1)]

As you can see, there are two parallel edges from 1 to 2 and I'd like to remove one of them:

>>> G.remove_edge(1,2)
>>> G.edges()
[(0, 1), (2, 0), (2, 1)]

But both of them got removed!

And it differs from example stated in the refrence of NetworkX:

>>> G = nx.MultiDiGraph() 
>>> G.add_edges_from([(1,2),(1,2),(1,2)])
>>> G.remove_edge(1,2) # remove a single (arbitrary) edge

All of them are vanished!

http://networkx.lanl.gov/reference/generated/networkx.MultiDiGraph.remove_edge.html

Christopher Ellison

unread,
Jun 5, 2010, 3:51:22 PM6/5/10
to networkx...@googlegroups.com
Nima wrote the following on 06/05/2010 12:48 PM:
> I've almost fixed the problem, but there's still something I can't
> figure out:
>
> >>> G = networkx.MultiDiGraph({0:[1], 1:[2, 2], 2:[1, 0]})
> >>> G.edges()
> [(0, 1), (1, 2), (1, 2), (2, 0), (2, 1)]
>
> As you can see, there are two parallel edges from 1 to 2 and I'd like to
> remove one of them:
>
> >>> G.remove_edge(1,2)
> >>> G.edges()
> [(0, 1), (2, 0), (2, 1)]
>
> But both of them got removed!
>
> And it differs from example stated in the refrence of NetworkX:
>
> >>> G = nx.MultiDiGraph()
> >>> G.add_edges_from([(1,2),(1,2),(1,2)])
> >>> G.remove_edge(1,2) # *remove a single (arbitrary) edge*

>
> All of them are vanished!
>

What version of NetworkX are you running? Have you tried the latest
version (if you are able). I seem to recall that the old version of
NetworkX had this issue and that it has been fixed (for a while now) in
more recent versions.

Chris

Nima

unread,
Jun 5, 2010, 4:14:37 PM6/5/10
to networkx...@googlegroups.com
2010/6/6 Christopher Ellison <cell...@cse.ucdavis.edu>

What version of NetworkX are you running?  Have you tried the latest version (if you are able).  I seem to recall that the old version of NetworkX had this issue and that it has been fixed (for a while now) in more recent versions.

Chris

You were right my friend! Now, it works like a charm :)
euler.py

Nima

unread,
Jun 15, 2010, 3:15:48 PM6/15/10
to networkx...@googlegroups.com
2010/6/1 Aric Hagberg <ahag...@gmail.com>

ps.  If you are interested in contributing the Fleury algorithm to NetworkX
we can help get it documented, tested, and included.


Well, I tried to contribute the algorithm to NetworkX, but it seems that you're not interested.

Nima

unread,
Jun 15, 2010, 3:29:25 PM6/15/10
to networkx...@googlegroups.com
And it works well for both directed and undirected graphs:

first-graph.png

second-graph.png
first-graph.png
second-graph.png

Nima

unread,
Jun 19, 2010, 1:52:59 PM6/19/10
to networkx...@googlegroups.com
Am I boycotted or something?!

Richard Careaga

unread,
Jun 19, 2010, 2:01:30 PM6/19/10
to networkx...@googlegroups.com
Of course not. Aric, who is the developer, does a good job of catching up on unanswered questions, but probably can't spend fulltime. This group may also not be the place for your posting, which if I'm right, was better suited to networkx-dev. Most of us here are beginners and not having anything useful to say, said nothing. Please don't feel slighted; if you really want to feel ignored, you could try setting up a blog like my two! As the song says, 'nobody loves me but my mother, and she could be jiving me too.' Good luck.

Nima wrote:
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.

franck kalala

unread,
Jun 19, 2010, 2:06:35 PM6/19/10
to networkx...@googlegroups.com
Nima for sure your effort will not be ignore,
W`ere a community.


2010/6/19 Richard Careaga <leu...@gmail.com>



--
***********************************************
***********************************************
Franck Kalala Mutombo
fra...@aims.ac.za
African Institut for Mathematical Sciences, Muizenberg Cape Town, South Africa
franck....@unilu.ac.cd
************************************************
************************************************

Nima

unread,
Jun 19, 2010, 2:48:04 PM6/19/10
to networkx...@googlegroups.com
2010/6/19 Richard Careaga <leu...@gmail.com>

Of course not. Aric, who is the developer, does a good job of catching up on unanswered questions, but probably can't spend fulltime. This group may also not be the place for your posting, which if I'm right, was better suited to networkx-dev. Most of us here are beginners and not having anything useful to say, said nothing. Please don't feel slighted; if you really want to feel ignored, you could try setting up a blog like my two! As the song says, 'nobody loves me but my mother, and she could be jiving me too.' Good luck.


Merci mon ami,
I also considered that Aric might be busy. But now, it's more than two weeks since I mailed the code and I haven't heard anything from you, even though he himself said that he would help me to get it documented, tested and included. And it made me to spend more time on the code than was needed for just a Discrete Math Project. I really love NetworkX and I just wanted to contribute to this great project.

Nima

unread,
Jun 19, 2010, 6:41:53 PM6/19/10
to networkx...@googlegroups.com
On Sat, Jun 19, 2010 at 10:31 PM, Richard Careaga <leu...@gmail.com> wrote:
This group may also not be the place for your posting, which if I'm right, was better suited to networkx-dev. Most of us here are beginners and not having anything useful to say, said nothing.


The discussion group which has been introduced in the NetworkX Developer Zone page (https://networkx.lanl.gov/trac) is this exact group (networkx-discuss).

It also states that:
"NetworkX is an open source project and we welcome contributions of code, documentation, examples, bug reports, and fixes or any other suggestions for improvements or features. "

I don't see any "underground" development group there!

Richard Careaga

unread,
Jun 19, 2010, 7:22:14 PM6/19/10
to networkx...@googlegroups.com
Apologies. Got my groups mixed.

Nima wrote:

Aric Hagberg

unread,
Jun 19, 2010, 8:12:52 PM6/19/10
to networkx...@googlegroups.com
On Sat, Jun 19, 2010 at 4:41 PM, Nima <nima...@gmail.com> wrote:
>> This group may also not be the place for your posting, which if I'm right,
>> was better suited to networkx-dev. Most of us here are beginners and not
>> having anything useful to say, said nothing.
>>
>
> The discussion group which has been introduced in the NetworkX Developer
> Zone page (https://networkx.lanl.gov/trac) is this exact group
> (networkx-discuss).
>
> It also states that:
> "NetworkX is an open source project and we welcome contributions of code,
> documentation, examples, bug reports, and fixes or any other suggestions for
> improvements or features. "
>
> I don't see any "underground" development group there!

There is an another (unused) mailing list but this is the right place to
come for all things NetworkX.

I sincerely appreciate your contribution; sometimes other projects
keep me busy but I do read all of the email here and try to get
to everything as best I can.

I added your code in a ticket on the development site at
https://networkx.lanl.gov/trac/ticket/363
where you see my further comments and an updated version.
I'll send you account information off-list.

Aric

Nima

unread,
Jun 20, 2010, 1:55:03 AM6/20/10
to networkx...@googlegroups.com
Thanks. I really appreciate this :)
I'll try to work on more algorithms in my free time this summer.
Reply all
Reply to author
Forward
0 new messages