自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

用 Python 繪制幾張有趣的可視化圖表

開發(fā) 后端
今天小編就來為大家介紹兩個用于繪制流程圖的模塊,我們先來看第一個。

流程圖存在于我們生活的方方面面,對于我們追蹤項目的進(jìn)展,做出各種事情的決策都有著巨大的幫助,而對于萬能的Python而言呢,繪制流程圖也是十分輕松的,今天小編就來為大家介紹兩個用于繪制流程圖的模塊,我們先來看第一個。

SchemDraw

那么在SchemDraw模塊當(dāng)中呢,有六個元素用來代表流程圖的主要節(jié)點的,橢圓形代表的是決策的開始和結(jié)束,代碼如下:

import schemdraw
from schemdraw.flow import *
with schemdraw.Drawing() as d:
d += Start().label("Start")

output

箭頭表示的是決策的走向,用來連接各個節(jié)點的,代碼如下:

with schemdraw.Drawing() as d:
d += Arrow(w = 5).right().label("Connector")

output

平行四邊形代表的是你所要去處理和解決的問題,而長方形所代表的是你所要為此做出的努力或者說是過程,代碼如下:

with schemdraw.Drawing() as d:
d += Data(w = 5).label("What's the problem")

output


with schemdraw.Drawing() as d:
d += Process(w = 5).label("Processing")

output

而菱形代表的則是決策的具體情況,代碼如下:

with schemdraw.Drawing() as d:
d += Decision(w = 5).label("Decisions")

output

我們來繪制一個簡單的流程圖,假如周末的時候我們想著要不要出去露營(Camping),那既然要去露營的話,我們肯定是需要查看一下天氣,看一下是否是晴天(Sunny),如果是下雨天(Rainy)的話,就不去,按照這種邏輯,我們來繪制一下流程圖,代碼如下:

import schemdraw
from schemdraw.flow import *
with schemdraw.Drawing() as d:
d+= Start().label("Start")
d+= Arrow().down(d.unit/2)
# 具體是啥問題嘞
d+= Data(w = 4).label("Go camping or not")
d+= Arrow().down(d.unit/2)
# 第一步 查看天氣
d+= Box(w = 4).label("Check weather first")
d+= Arrow().down(d.unit/2)
# 是否是晴天
d+= (decision := Decision(w = 5, h= 5,
S = "True",
E = "False").label("See if it's sunny"))
# 如果是真的話
d+= Arrow().length(d.unit/2)
d+= (true := Box(w = 5).label("Sunny, go camping"))
d+= Arrow().length(d.unit/2)
# 結(jié)束
d+= (end := Ellipse().label("End"))
# 如果不是晴天的話
d+= Arrow().right(d.unit).at(decision.E)
# 那如果是下雨天的話,就不能去露營咯
d+= (false := Box(w = 5).label("Rainy, stay at home"))
# 決策的走向
d+= Arrow().down(d.unit*2.5).at(false.S)
# 決策的走向
d+= Arrow().left(d.unit*2.15)
d.save("palindrome flowchart.jpeg", dpi = 300)

output

Networkx

Networkx模塊用來創(chuàng)建和處理復(fù)雜的圖網(wǎng)絡(luò)結(jié)構(gòu),生成多種隨機網(wǎng)絡(luò)和經(jīng)典網(wǎng)絡(luò),分析網(wǎng)絡(luò)結(jié)構(gòu)和建立網(wǎng)絡(luò)模型,例如在繪制人脈關(guān)系網(wǎng)的案例當(dāng)中就可以用到networkx模塊,

而例如一個公司的組織架構(gòu)圖,也可以用到該模塊,來簡單直觀的繪制公司的整體架構(gòu),代碼如下:

import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
G = nx.DiGraph()
nodes = np.arange(0, 8).tolist()
G.add_nodes_from(nodes)
# 節(jié)點連接的信息,哪些節(jié)點的是相連接的
G.add_edges_from([(0,1), (0,2),
(1,3), (1, 4),
(2, 5), (2, 6), (2,7)])
# 節(jié)點的位置
pos = {0:(10, 10),
1:(7.5, 7.5), 2:(12.5, 7.5),
3:(6, 6), 4:(9, 6),
5:(11, 6), 6:(14, 6), 7:(17, 6)}
# 節(jié)點的標(biāo)記
labels = {0:"CEO",
1: "Team A Lead",
2: "Team B Lead",
3: "Staff A",
4: "Staff B",
5: "Staff C",
6: "Staff D",
7: "Staff E"}
nx.draw_networkx(G, pos = pos, labels = labels, arrows = True,
node_shape = "s", node_color = "white")
plt.title("Company Structure")
plt.show()

output

看到這里,大家可能會覺得會指出來的結(jié)果有點簡單,想要添加上去些許顏色,代碼如下:

nx.draw_networkx(G, pos = pos, labels = labels,  
bbox = dict(facecolor = "skyblue",
boxstyle = "round", ec = "silver", pad = 0.3),
edge_color = "gray"
)
plt.title("Company Structure")
plt.show()

output

責(zé)任編輯:龐桂玉 來源: AI科技大本營
相關(guān)推薦

2022-05-16 09:34:17

Python可視化圖表

2021-10-11 08:04:22

Python數(shù)據(jù)行程

2015-08-20 10:04:40

可視化

2020-03-01 14:01:22

Echarts數(shù)據(jù)可視化圖表

2024-05-22 16:03:49

2023-06-11 16:12:14

數(shù)據(jù)可視化圖表類型

2023-08-01 16:01:59

可視化Seaborn

2023-10-07 09:34:03

數(shù)據(jù)可視化

2019-07-26 09:19:32

數(shù)據(jù)可視化架構(gòu)

2021-04-09 10:42:03

數(shù)據(jù)可視化框架大數(shù)據(jù)

2022-05-30 08:37:34

可視化圖表項目開源

2017-05-23 09:07:48

可視化圖表視覺

2022-08-26 09:15:58

Python可視化plotly

2022-07-13 15:54:14

Matplotlib圖表

2019-05-28 11:52:43

可視化圖表數(shù)據(jù)

2020-03-11 14:39:26

數(shù)據(jù)可視化地圖可視化地理信息

2022-11-28 15:04:42

數(shù)據(jù)可視化工具

2022-07-25 10:07:26

Python可視化技巧

2020-11-02 13:54:41

Python可視化決策樹

2020-10-31 17:13:04

Python可視化Seaborn
點贊
收藏

51CTO技術(shù)棧公眾號