Using Networkx to draw graph
Author
posted @ 2014年4月13日 14:51
in Python
, 22795 阅读
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.
2023年10月01日 18:54
Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. Seo Ajansı
2023年10月03日 23:30 Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. trade digital assets
2023年12月03日 22:08 Trust 커뮤니티 토토매치 for a safe and entertaining betting journey. Their transparency, quick payouts, and user-friendly platforms are unbeatable.
2023年12月04日 08:02
백링크하이's commitment to quality backlinks is unmatched. They're a game-changer in the SEO industry.
2023年12月07日 03:29
op사이트 순위 rankings are your gateway to online brilliance.
2023年12月08日 23:08
오피가이드 ensures you're always in the loop about the latest OP trends. Trust it for accurate information and hassle-free OP exploration.
2023年12月11日 03:55 Elevate your nightlife experiences with 오피가이드's user-generated content.
2023年12月11日 04:03
안전카지노's gaming license is proof of its legitimacy. You're in safe hands here.
2023年12月11日 20:47
I had an incredible experience with 제주출장마사지. The hot stone massage was divine, and their therapists are truly skilled.
2023年12月11日 21:04
부산오피 caters to diverse tastes. Whether you're a local or a tourist, you'll find Officetels to suit your preferences.
2023年12月11日 23:31
에볼루션카지노's live blackjack is my favorite. The professional dealers and high-quality streaming make it an exceptional experience. Try it for yourself!
2023年12月12日 01:32
No more officetel guesswork with 오피가이드.
2023年12月14日 05:29
Hey your site looks a little bit weird in Opera on my office computer Mac . NBA중계
2023年12月15日 22:50
Oga's 출장마사지 is my go-to for relaxation. Their therapists are exceptional, and the convenience is unbeatable.
2023年12月16日 02:20
밤의민족: Your night-time companion for 'OP' adventures and tranquil home Thai massages.
2023年12月16日 23:21
대전오피's services are second to none. Every visit is a rejuvenating experience.
2023年12月17日 04:47 I'm addicted to 해외축구중계. It's a one-stop-shop for all my soccer needs.
2023年12月18日 04:17
Effortlessly find officetel wonders with 오피가이드. It's the officetel enthusiast's ultimate resource for discovering hidden gems.
2023年12月18日 20:09
The user-friendly interface of 티비위키 is a breath of fresh air.
2023年12月19日 22:30
Great weblog here! Also your web site lots up very fast! What host are you the usage of? Can I am getting your affiliate hyperlink for your host? I want my web site loaded up as fast as yours lol. 에볼루션카지노
2023年12月20日 08:36
I read about 대전휴게텔 on The Insider's Views. It's as amazing as they described.
2024年1月02日 04:23
오피가이드 is my trusted companion for discovering massage parlors in KOREA.
2024年1月22日 22:29
This is my first-time i visit here. I found a multitude of entertaining stuff as part of your blog, especially its discourse. From the tons of comments on the posts, I guess I am not the only one having most of the enjoyment the following! Keep in the excellent job. The Presidential Family
2024年1月22日 22:32
This is my first-time i visit here. I found a multitude of entertaining stuff as part of your blog, especially its discourse. From the tons of comments on the posts, I guess I am not the only one having most of the enjoyment the following! Keep in the excellent job. The Presidential Family
2024年2月02日 17:50
Hello there, just became alert to your blog through Google, and found that it’s really informative. I’m going to watch out for brussels. I will be grateful if you continue this in future. A lot of people will be benefited from your writing. Cheers!
2024年2月03日 20:15
Thanks so much regarding giving me personally an update on this subject matter on your site. Please know that if a completely new post becomes available or if perhaps any improvements occur on the current submission, I would consider reading a lot more and learning how to make good use of those techniques you discuss. Thanks for your time and consideration of other men and women by making this website available. holiday in cuba Büyükçekmece Escort
2024年2月07日 01:39
My husband and i were quite thrilled when Chris could finish up his investigations with the ideas he obtained out of the web site. It is now and again perplexing to simply possibly be giving out tactics which usually others could have been making money from. And we remember we have got the blog owner to give thanks to for that. The explanations you’ve made, the straightforward blog menu, the friendships you can aid to create – it is everything superb, and it is making our son and the family do think that idea is fun, and that’s pretty essential. Thanks for everything! <a href="https://www.jpost.com/brandblend/sugar-defender-reviews-fraud-or-legit-2024-beware-scam-warning-and-fake-side-effects-784867">Sugar Defender</a>
2024年2月10日 17:43
There is numerous separate years Los angeles Weight reduction eating plan with each a person is a necessity. The pioneer part can be your original getting rid of belonging to the extra pounds. la weight loss 인계동노래방
2024年2月11日 01:23
You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. sevilla
2024年2月11日 23:12
You’ve made various nice points there. I did specific search terms around the matter and found mainly individuals will believe your site Blox Fruits codes
2024年2月12日 00:20
I impressed, I must say. Actually hardly ever do I encounter a blog that each educative and entertaining, and let me let you know, you have got hit the nail on the head. Your concept is outstanding; the difficulty is something that not enough people are talking intelligently about. I am very glad that I stumbled across this in my search for something regarding this. Best price for battery tab
2024年2月12日 01:52
I was curious if you ever considered changing the page layout of your blog? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two pictures. Maybe you could space it out better? Napsgear
2024年4月09日 14:18
Strange this post is totaly unrelated to what I was searching google for, but it surely was once indexed at the first page. I suppose your doing something proper if Google likes you enough to place you at the first page of a non related search. <a href="https://soundcamps.com/tiktok-music-promotion/">Sell NFT on TikTok</a>
2024年4月10日 02:17
Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include.
2024年4月15日 06:13
I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site.
2024年4月18日 08:24
Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include.
2024年4月18日 20:03
Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include.
2024年8月28日 20:50
If more people that write articles really concerned themselves with writing great content like you, more readers would be interested in their writings. Thank you for caring about your content. sundabet
2024年9月07日 21:11
Excellent insights! For more tips on digital marketing and staying competitive, visit digitad. Highly recommended!
2024年9月25日 00:06
Great insights in this article! For anyone looking to explore related themes further, FlixHQ offers a fantastic selection of documentaries and series on the topic. Highly recommended!
2024年9月25日 19:50
The subsequent time I learn a blog, I hope that it doesnt disappoint me as a lot as this one. I mean, I know it was my option to read, however I really thought youd have something attention-grabbing to say. All I hear is a bunch of whining about something that you possibly can repair when you werent too busy on the lookout for attention. <a href="https://hudson9s12mvb8.wikibuysell.com/user">Result Macau 5D</a>
2024年10月11日 05:09
Fantastic insights in this blog! For more trending content and videos, check out Urlebird—your go-to platform for all things viral.
2024年11月16日 09:16
You always manage to keep things fresh.
2024年11月17日 23:42
Great insights shared in this blog! If you're into bold and nostalgic fashion, check out Y2koutfits for the latest trends that scream 2000s style!
2024年11月18日 08:12
Thanks for sharing this quality information with us. I really enjoyed reading. Will surely going to share this URL with my friends. biurka dla dzieci