You can try it with copy! Let's draw a cool network diagram with networkx of Python

Let's draw a network diagram with networkx that can draw a cool network diagram during winter vacation

Do you have a good winter vacation? Our company is really grateful to the mice for taking a rest from 28th to 5th.

However, I think that engineers should train McRefugees to improve their skills at such times.

Today, I will introduce a library called networkx that allows you to draw network diagrams.

--Time required for this work: About 10 minutes --What to prepare

Installation

(venv)$pip install networkx

First, load the data with pandas

import pandas as pd
df_links = pd.read_csv('https://microlearning.site/pydata/ch8/links.csv')
df_links.head(20)

Make sure a table like the one below is loaded. The related networks are 1.

image.png

Finally draw a network diagram

The drawing of the network diagram is as follows.

import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
NUM = len(df_links.index)
for i in range(1,NUM+1):
    node_no = df_links.columns[i].strip("Node")#Removed the word "Node"
    G.add_node(str(node_no))

for i in range(NUM):
    for j in range(NUM):
        if df_links.iloc[i][j] == 1:
            G.add_edge(str(i),str(j))

nx.draw_networkx(G,nide_color="k",edge_color="k",font_color="w")
plt.show()

Let me give you a rough idea of what you're doing, first add a node A line connects the parts of the table where the nodes are 1 (related parts).

Then, the following network diagram will be displayed (the display will be different each time). The numbers that are closely related to each node come to the center. (4, 5, etc.)

image.png

Thank you for your hard work. The shape changes each time you run it. try it.

Change log

--2020/1/1 Newly created

Recommended Posts

You can try it with copy! Let's draw a cool network diagram with networkx of Python
[Python] Draw a Qiita tag relationship diagram with NetworkX
You can do it with Python! Structural analysis of two-dimensional colloidal crystals
Try to draw a life curve with python
You can easily create a GUI with Python
Draw a graph with NetworkX
Let's create a PRML diagram with Python, Numpy and matplotlib.
Try to automate the operation of network devices with Python
Draw a graph with networkx
Let's make a diagram that can be clicked with IPython
Let's make a GUI with python.
Python | What you can do with Python
[Python] If you want to draw a scatter plot of multiple clusters
"Manim" that can draw animation of mathematical formulas and graphs with Python
Try to solve a set problem of high school math with Python
Let's make a shiritori game with Python
[Python] Wouldn't it be the best and highest if you could grasp the characteristics of a company with nlplot?
Make a relation diagram of Python module
Let's create a free group with Python
Let's make a voice slowly with Python
Try HTML scraping with a Python library
Let's make a web framework with Python! (1)
Let's make a Twitter Bot with Python!
Until you can use opencv with python
Let's make a web framework with Python! (2)
Since python is read as "Pichon", it can be executed with "Pichon" (it is a story)
If you guys in the scope kitchen can do it with a margin ~ ♪
Let's draw the voltage of the digital multimeter 34461A of the measuring instrument Keysight with CircuitPython
If you want to make a discord bot with python, let's use a framework
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Draw a graph of a quadratic function in Python
Try it with Word Cloud Japanese Python JupyterLab.
[Python] Draw a directed graph with Dash Cytoscape
Make a copy of the list in Python
You can see it! Comparison of optimization methods (2020)
Try to make a "cryptanalysis" cipher with Python
[Python] Draw a Mickey Mouse with Turtle [Beginner]
Let's write a Python program and run it
Try to make a dihedral group with Python
Consideration when you can do a good job in 10 years with Python3 and Scala3.
Can you study with a minimum of belongings? Developed on iPad << 3rd >> ~ Savior Appears ~
Get a large amount of Starbucks Twitter data with python and try data analysis Part 1
Until you can install blender and run it with python for the time being
Until you create a machine learning environment with Python on Windows 7 and run it
[For super beginners] Python environment construction & scraping & machine learning & practical application that you can enjoy by moving with copy [Let's find a good rental property with SUUMO! ]