Using Networkx to draw graph
Author
posted @ 2014年4月13日 14:51
in Python
, 14907 阅读
Draw a directed graph using Networkx
Code :
try: import matplotlib.pyplot as plt except: raise import networkx as nx G=nx.DiGraph() # Add nodes by specifying their positions G.add_node('10', pos=(2, 10)) G.add_node('9', pos=(4, 9)) G.add_node('8', pos=(0, 13)) G.add_node('7', pos=(1.5, 4)) G.add_node('6', pos=(4, 4)) G.add_node('5', pos=(6, 11)) G.add_node('3', pos=(6, 6)) G.add_node('0', pos=(0, 0)) # Add edges by defining weight and label G.add_edge('10','9',weight=1, label='I') G.add_edge('10','8',weight=1, label='I') G.add_edge('10','7',weight=1, label='I') G.add_edge('9','3', weight=1, label='I') G.add_edge('9','6',weight=1, label='I') G.add_edge('9','5',weight=1, label='I') G.add_edge('7','0',weight=1, label='I') G.add_edge('7','6',weight=0, label='II') G.add_edge('6','3',weight=0, label='II') G.add_edge('5','3',weight=0, label='II') elarge=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] >0.5] # solid edge esmall=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] <=0.5] # dashed edge # Retrieve the positions from graph nodes and save to a dictionary pos=nx.get_node_attributes(G,'pos') # Draw nodes nx.draw_networkx_nodes(G,pos,node_size=700, node_color='orange') # Draw edges nx.draw_networkx_edges(G,pos,edgelist=elarge, width=2, edge_color='g') nx.draw_networkx_edges(G,pos,edgelist=esmall, arrows=False, width=3, alpha=0.5,edge_color='b',style='dashed') # Draw node labels nx.draw_networkx_labels(G,pos,font_size=18,font_family='sans-serif') # Draw edge labels edge_labels =dict([((u, v), d['label']) for u, v, d in G.edges(data=True)]) nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels) plt.axis('off') plt.savefig("communication_authority_graph.eps", format='eps') # save as eps plt.show() # display
References:
2021年10月10日 06:43
Best Social Plan is the most trusted company for providing social media marketing services. Best Social Plan
2021年10月29日 07:35
I can’t believe that this printing center has the ability to deliver my orders at an amazing speed. The print and the papers were both of high quality. https://www.digitekprinting.com/vinyl-banners this link to know more about their awesome services.
2022年3月11日 07:17
Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. Leedon Green
2022年4月09日 08:39
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. najbolji brokeri u hrvatskoj
2022年4月17日 05:32
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this... Ki Residences
2022年7月14日 17:12
Pg Slot สล็อต เว็บตรง เว็บสล็อตออนไลน์ แตกง่ายจ่ายจริง แจกหนัก แตกหนัง กับ เว็บ pg-slot.game ของเรา ที่กำลังมาแรง แซงเว็บเกมอันดับต้น ๆ ไปหมดแล้ว สมัครสมาชิกได้แล้ววันนี้
2022年9月16日 04:08
Environmental Education or Environmental Studies (EVS) was introduced from the foundation of education to enable students to understand the situations occurring around our surroundings without any difficulties. NCERT Evs Sample Paper Class 2 The subject refers to the neighbouring in which all life, also makes use of to solve day-to-day challenges involving the environmental elements.To get a complete analysis of examination question pattern and to get ready to write an exam with confidence, subject experts of the NCERT has provided the Class 2 EVS Sample Paper 2023 with study & learning material that supports all formats of exams held under Term-1, Term-2 and other types of exams for every interested candidate.
2022年9月16日 04:10
Environmental Education or Environmental Studies (EVS) was introduced from the foundation of education to enable students to understand the situations occurring around our surroundings without any difficulties. NCERT Evs Sample Paper Class 2 The subject refers to the neighbouring in which all life, also makes use of to solve day-to-day challenges involving the environmental elements.To get a complete analysis of examination question pattern and to get ready to write an exam with confidence, subject experts of the NCERT has provided the Class 2 EVS Sample Paper 2023 with study & learning material that supports all formats of exams held under Term-1, Term-2 and other types of exams for every interested candidate.
2023年7月10日 18:40
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it. https://ulnames.com/military-team-names/
2023年7月10日 18:44
Personally I think overjoyed I discovered the blogs. https://www.adiwarna.co.id/fire-suppression-system/
2023年7月19日 20:47
I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... Fun 88
2023年7月21日 18:57 I don t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site. rental mobil banyuwangi
2023年7月21日 21:23
It is the intent to provide valuable information and best practices, including an understanding of the regulatory process. Jun88
2023年7月23日 16:20 It's late finding this act. At least, it's a thing to be familiar with that there are such events exist. I agree with your Blog and I will be back to inspect it more in the future so please keep up your act. ns2121 login
2023年7月23日 17:05
This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. slot gacor hari ini
2023年7月23日 18:05
Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. Streetwear clothing
2023年7月23日 19:05
Dalam era digital yang terus berkembang, kesempatan untuk menghasilkan uang secara online semakin beragam. Salah satu platform yang sangat populer untuk mencari penghasilan adalah YouTube. Bukan hanya para pembuat konten yang dapat menghasilkan uang melalui YouTube, tapi juga para penontonnya. aplikasi nonton youtube dapat uang
2023年7月24日 20:44 If you don"t mind proceed with this extraordinary work and I anticipate a greater amount of your magnificent blog entries dewacukong88
2023年7月24日 22:09
Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share. ny zipline adventure tours hunter mountain
2023年7月26日 10:00
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. elmer t lee for sale
2023年7月26日 10:51
A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Study Abroad Consultants in Trivandrum
2023年7月27日 04:47
We are tied directly into the sate’s renewal database which allows us to process your request almost instantly. thevang1.net
2023年8月27日 19:43
Celebrate the upcoming arrival of a little one with our range of Neutral Baby Shower Gifts. These gifts are carefully curated to suit any baby shower theme or colour palette. From practical diaper bags to heartwarming story books, our neutral collection ensures that every gift is a delightful surprise, regardless of gender.
2023年8月27日 23:57
Exploring Saint Lucia is effortless with Tour Saint Lucia's local taxi services. Our knowledgeable drivers provide insights into the best local spots and attractions. Whether you're visiting landmarks, indulging in culinary delights, or shopping for souvenirs, our local taxi services make every journey enjoyable and informative.