python 交互式流程圖_使用Python創建漂亮的交互式和弦圖

python 交互式流程圖

Python中的數據可視化 (Data Visualization in Python)

R vs Python is a constant tussle when it comes to what is the best language, according to data scientists. Though each language has it’s strengths, R, in my opinion has one cutting-edge trick that is hard to beat — R has fantastic tools to communicate results through visualization.

根據數據科學家的說法,R還是Python一直是爭論最佳語言的話題。 盡管每種語言都有自己的長處,但我認為R具有一個難以克服的尖端技巧-R具有出色的工具,可以通過可視化傳達結果。

This particular point stood out to me this week, when I was trying to find an appealing way to visualize the correlation between features in my data. I stumbled upon CHORD Diagrams!(Which we will get to, in a minute) I had seen a few R examples to generate Chord Diagrams using Circlize where you could just pass the properly shaped data to the chordDiagram() function and ta-da!

本周,當我試圖找到一種吸引人的方式來可視化數據中要素之間的相關性時,這一點對我而言尤為突出。 我偶然發現了和弦圖表!(我們將拿地,在一分鐘內),我已經看到了一些[R例子使用Circlize在那里你可以只在適當形狀的數據傳遞給chordDiagram()函數和當當生成和弦圖表!

You should have seen the look on my face when I found the Python Plotly implementation of the Chord Diagram. Even to get a basic figure, one had to put in a lot of effort. The end result simply did not seem worth the effort. I was almost dropping the idea of using a Chord Diagram, when I stumbled upon chord on pypi.

當我發現Chord Diagram的Python Plotly實現時,您應該已經看到了我的表情。 即使要獲得一個基本的數字,也必須付出很多努力。 最終結果似乎根本不值得付出努力。 當我偶然發現pypi的和弦時,我幾乎放棄了使用和弦圖的想法。

好的,和弦圖是什么? (Okay, What is a Chord Diagram?)

A Chord Diagram represents the flows between a set of distinct items. These items known as nodes are displayed all around a circle and the flows are shown as connections between the nodes, shown as arcs.

和弦圖表示一組不同項目之間的流程。 這些稱為節點的項目顯示在整個圓周圍,并且流程顯示為節點之間的連接,顯示為圓弧。

If that did not explain it clearly, let’s take a look at an example:

如果那不能清楚地解釋它,讓我們看一個例子:

Image for post
Image by the Author
圖片由作者

The above Chord Diagram, visualizes the number of times two entities(Cities in this case) occur together in the itinerary of a traveler, it allows us to study the flow between them.

上面的弦圖,可視化了兩個實體(在這種情況下為城市)在一個旅行者的行程中一起出現的次數,它使我們能夠研究它們之間的流動。

如何以最小的努力創建漂亮的和弦圖? (How to create a beautiful Chord Diagram with minimum effort?)

Let me take you through the process of data preparation and then the creation of the Chord Diagram.

讓我引導您完成數據準備過程,然后創建和弦圖。

安裝: (Installation:)

Assuming Pandas is already installed, You need to install the chord package from pypi, using —

假設已經安裝了Pandas,則需要使用以下方法從pypi安裝和弦包:

pip install chord

數據準備: (Data Preparation:)

I am using the Boston House Prices Dataset, which can be downloaded from here.

我使用的是波士頓房屋價格數據集,可從此處下載。

# importing Pandas libary
import pandas as pd# reading data from csv
df = pd.read_csv("housing.csv")

My goal, here is to visualize the correlation between the feature in the dataset. So, for the sake of brevity, I will drop a few of the columns. I will be left with only 6 features. (You can skip this if you wish)

我的目標是可視化數據集中要素之間的相關性。 因此,為了簡潔起見,我將刪除一些專欄文章。 我將只剩下6個功能。 (如果愿意,可以跳過此步驟)

# List of columns to delete and then dropping them.
delete = ['ZN', 'INDUS', 'CHAS', 'DIS','RAD','PTRATIO','B','LSTAT']df.drop(delete, axis=1, inplace=True)

Now let’s create the correlation matrix using Pandas corr() function.

現在,讓我們使用Pandas corr()函數創建相關矩陣。

# Now, matrix contains a 6x6 matrix of the values.
matrix = df.corr()# Replacing negative values with 0’s, as features can be negatively correlated.
matrix[matrix < 0] = 0# Multiplying all values by 100 for clarity, since correlation values lie b/w 0 and 1.
matrix = matrix.multiply(100).astype(int)# Converting the DataFrame to a 2D List, as it is the required input format.
matrix = matrix.values.tolist()

This data is now perfect for our plotting!

現在,該數據非常適合我們的繪圖!

繪制圖表: (Plotting the Chart Diagram:)

The only step left before plotting, is storing the names of the entities as a list. In my case, these are the names of the features.

繪制之前剩下的唯一步驟是將實體名稱存儲為列表。 就我而言,這些是功能的名稱。

# Names of the features.
names = ["Crime Rate","N-Oxide","Number of rooms","Older buildings","Property Tax","Median Price"]

Now, all we have to do is import the package —

現在,我們要做的就是導入包-

from chord import Chord

Then pass the matrix and the names to the Chord() function.

然后將矩陣和名稱傳遞給Chord()函數。

Chord(matrix, names).show()#Note: The show() function works only with Jupyter Labs.
# (Not Jupyter notebook)

This will be your output:

這將是您的輸出:

Image for post
Output in Jupyter Lab. Image by Author.
Jupyter Lab中的輸出。 圖片由作者提供。

Before we go further and explore the other style and output settings available in the Chord library, let’s take a look at what the output represents.

在進一步探討Chord庫中可用的其他樣式和輸出設置之前,讓我們看一下輸出所代表的含義。

As you can see, when you hover on the Crime rate, you can see that it is connected to Property Tax, Older Buildings and level of N-Oxide, but has no connections with the Median Price or the Number of Rooms. You can now hover on the connection and you will see the correlation value between these features.

如您所見,當您將鼠標懸停在犯罪率上時,您會看到它與物業稅,舊建筑物和N-氧化物水平相關,但與中位數價格或房間數沒有關系。 您現在可以將鼠標懸停在連接上,您將看到這些功能之間的相關性值。

You might notice that the Median Price is 100% correlated with itself, which is the case with all the features. That happens because we get a perfect correlation value when we compare a feature against itself. We can fix this with a single line of code, if you wish.

您可能會注意到,中位數價格與其自身100%相關,所有功能都是這種情況。 發生這種情況的原因是,當我們將特征與自身進行比較時,我們獲得了完美的相關值。 如果您愿意,我們可以用一行代碼來解決。

# Operate on the data before converting it into a 2D List# We are just converting all Perfect correlation 100's(Basically the 1’s) to 0 as well.
matrix[matrix == 100] = 0
matrix = matrix.values.tolist()

Here is your output, a much cleaner Chord Diagram:

這是您的輸出,更清晰的和弦圖:

Image for post
Image by Author
圖片作者

將和弦圖導出為HTML: (Export the Chord Diagram as HTML:)

Since the package uses d3-chord at it’s core, it also gives us the option to output the ChordDiagram as a completely editable HTML file! How cool is that?

由于該軟件包的核心使用d3-chord,因此它還為我們提供了將ChordDiagram輸出為完全可編輯HTML文件的選項! 多么酷啊?

Again, a single method call will do it for you —

同樣,一個方法調用將為您完成—

Chord(matrix, names).to_html()# This will create a file 'out.html' in your current directory.

You can open the HTML in a browser to find the same interactive Chord Diagram or you can open the .html in a code editor and customize the rest of your page!

您可以在瀏覽器中打開HTML以找到相同的交互式和弦圖,也可以在代碼編輯器中打開.html并自定義頁面的其余部分!

Here’s my output,

這是我的輸出,

Image for post
Output in the form of HTML. Image by Author.
以HTML形式輸出。 圖片由作者提供。

What I have done is extremely basic. The point is, output as a HTML opens up a myriad of possibilities to use the Chord Diagram.

我所做的工作非常基礎。 關鍵是,以HTML格式輸出將打開使用和弦圖的多種可能性。

樣式和自定義: (Styling and Customization:)

顏色: (Colors:)

You can change the colors of the Chord Diagram by passing any colors from the d3 categorical palette. You can find samples of the outputs on the Official Guide. But here are a couple of examples:

您可以通過傳遞d3分類調色板中的任何顏色來更改和弦圖的顏色。 您可以在《 官方指南》中找到輸出示例。 但是這里有幾個例子:

# Just add the colors parameter and pass the value.
Chord(matrix, names, colors="d3.schemeDark2").show()
Image for post
Image by Author
圖片作者
# Just add the colors parameter and pass the value.
Chord(matrix, names, colors="d3.schemeAccent").show()
Image for post
Image by Author
圖片作者
# Add all the colors to a list.
coloursList = ["#f50057", "#2196f3", "#00e676", "#ff5722", "#00000", "#ff9100"]# Pass the list to the colors parameter.
Chord(matrix, names, colors=coloursList).show()
Image for post
Image by Author
圖片作者

Other customization's:

其他定制:

You can customize the labels and the opacity as well, checkout the official guide for that.

您也可以自定義標簽和不透明度,請查看官方指南。

結論: (Conclusions:)

Creating visualizations is almost always a part of a Data Scientist’s work. Part is the keyword here, because it means you cannot spend a lot of time to get them in shape and that is why we look for options that provide a simple yet functional implementation. That’s what I try to explore in this article, by creating an effective Chord Diagram with minimal effort.

創建可視化幾乎總是一個數據科學家的工作的一部分part是這里的關鍵字,因為它意味著您不能花費大量時間來使它們成形,因此這就是我們尋找提供簡單但功能性實現的選項的原因。 這就是我通過最小的努力創建有效的Chord Diagram來嘗試的方法。

This is my first work of technical writing and I have attempted to embed all the best practice that I have come across in my years of reading excellent content from this community. I’d appreciate feedback about any aspects of my work.

這是我的第一篇技術寫作著作,我試圖將多年來閱讀該社區優秀內容所遇到的所有最佳實踐嵌入其中。 感謝您對我的工作的各個方面的反饋。

其他資源: (Additional resources:)

[1] Official Guide — Shahin Rostami’s blog(Author of the library)

[1] 官方指南 -Shahin Rostami的博客(圖書館作者)

[2] chord on PyPi — You can download the package here.

[2] PyPi上的和弦 —您可以在此處下載軟件包。

翻譯自: https://towardsdatascience.com/create-beautiful-and-interactive-chord-diagrams-using-python-cb5ecb092a7c

python 交互式流程圖

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389167.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389167.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389167.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

機器學習解決什么問題_機器學習幫助解決水危機

機器學習解決什么問題According to Water.org and Lifewater International, out of 57 million people in Tanzania, 25 million do not have access to safe water. Women and children must travel each day multiple times to gather water when the safety of that water …

遞歸原來可以so easy|-連載(3)

本期我們再通過幾個例子&#xff0c;加深遞歸的理解和熟練度。 上期有一個練習題&#xff1a;用遞歸逆序輸出一個包含整型數據的鏈表。 先完成這個練習題。 對于程序員來說&#xff0c;代碼是最好的溝通工具&#xff0c;什么都不說&#xff0c;上代碼&#xff1a; public class…

Viewport3D 類Viewport3D 類Viewport3D 類

.NET Framework 類庫Viewport3D 類更新&#xff1a;2007 年 11 月為三維可視內容提供呈現圖面。命名空間&#xff1a; System.Windows.Controls程序集&#xff1a; PresentationFramework&#xff08;在 PresentationFramework.dll 中&#xff09;用于 XAML 的 XMLNS&#xf…

升級android 6.0系統

How to Fix errors by manually flashing Marshmallow update 鏡像下載for nexus Factory image Step 1: Download the [Marshmallow factory image](http://www.theandroidsoul.com/download-mra58k-android-6-0-marshmallow-update-released-for-nexus-5-nexus-6-nexus-9-n…

AGC 022 B - GCD Sequence

題面在這里&#xff01; 鍛煉腦子的小構造題。。。 一開始被 a[]<30000 且 序列 gcd 1所困擾&#xff0c;但是發現這并沒有什么&#xff0c;因為我接下來發現了一種總是能構造出 序列和是6的倍數的方案。 首先如果 n3 的話輸出樣例&#xff0c;因為只有這種情況沒法用我的方…

最接近原點的 k 個點_第K個最接近原點的位置

最接近原點的 k 個點In this article, I will be explaining to you one of the problems that you may find when tackling questions in data structures and algorithm. You will need some basic knowledge of data structures in order to understand the optimized solut…

網絡瀏覽器如何工作

Behind the scenes of modern Web Browsers現代Web瀏覽器的幕后花絮 The Web Browser is inarguably the most common portal for users to access the web. The advancement of the web browsers (through the series of history) has led many traditional “thick clients”…

讓自己的頭腦極度開放

為什么80%的碼農都做不了架構師&#xff1f;>>> 一. 頭腦封閉和頭腦開放 頭腦封閉 你是否經常有這樣的經歷&#xff0c;在一次會議或者在一次小組討論時&#xff0c;當你提出一個觀點而被別人否定時&#xff0c;你非常急迫地去反駁別人&#xff0c;從而捍衛自己的尊…

簡介DOTNET 編譯原理 簡介DOTNET 編譯原理 簡介DOTNET 編譯原理

簡介DOTNET 編譯原理 相信大家都使用過 Dotnet &#xff0c;可能還有不少高手。不過我還要講講Dotnet的基礎知識&#xff0c;Dotnet的編譯原理。 Dotnet是一種建立在虛擬機上執行的語言&#xff0c;它直接生成 MSIL 的中間語言&#xff0c;再由DotNet編譯器 JIT 解釋映象為本機…

RecyclerView詳細了解

關于RecyclerView大家都不陌生了&#xff0c;它的使用也越來越受歡迎&#xff0c;現在總體了解一下RecyclerView的作用&#xff0c;為什么會有RecyclerView呢&#xff0c;我用ListView也能干所有的事情啊&#xff0c;尺有所短&#xff0c;寸有所長&#xff0c;先來看看Recycler…

案例與案例之間的非常規排版

In 1929 the Cond Nast publishing group brought Russian-born Mehemed Fehmy Agha—who had been working for the German edition of Vogue magazine—to America as art director for House & Garden, Vanity Fair, and the senior edition of Vogue.1929年&#xff0c…

熊貓分發_熊貓新手:第二部分

熊貓分發This article is a continuation of a previous article which kick-started the journey to learning Python for data analysis. You can check out the previous article here: Pandas for Newbies: An Introduction Part I.本文是上一篇文章的延續&#xff0c;該文…

淺析微信支付:申請退款、退款回調接口、查詢退款

本文是【淺析微信支付】系列文章的第八篇&#xff0c;主要講解商戶如何處理微信申請退款、退款回調、查詢退款接口&#xff0c;其中有一些坑的地方&#xff0c;會著重強調。 淺析微信支付系列已經更新七篇了喲&#xff5e;&#xff0c;沒有看過的朋友們可以看一下哦。 淺析微信…

view工作原理-計算視圖大小的過程(onMeasure)

view的視圖有兩種情況&#xff1a; 內容型視圖&#xff1a;由視圖的內容決定其大小。圖形型視圖&#xff1a;父視圖為view動態調整大小。 ### measure的本質 把視圖布局使用的“相對值”轉化成具體值的過程&#xff0c;即把WRAP_CONTENT,MATCH_PARENT轉化為具體的值。 measur…

[轉載]使用.net 2003中的ngen.exe編譯.net程序

ngen.exe程序為.net 2003自帶&#xff0c; 在&#xff1a;/windows/microsoft.net/framework/v1.1.4322目錄下ngen.exe ngen能把.net框架的東西編譯成機器碼.... 網友&#xff1a;Visual Studio .NET 2003程序的運行速度怎么樣&#xff0c;我有一個感覺&#xff0c;V…

基于Redis實現分布式鎖實戰

背景在很多互聯網產品應用中&#xff0c;有些場景需要加鎖處理&#xff0c;比如&#xff1a;秒殺&#xff0c;全局遞增ID&#xff0c;樓層生成等等。大部分的解決方案是基于DB實現的&#xff0c;Redis為單進程單線程模式&#xff0c;采用隊列模式將并發訪問變成串行訪問&#x…

數據分析 績效_如何在績效改善中使用數據分析

數據分析 績效Imagine you need to do a bank transaction, but the website is so slow. The page takes so much time to load, all you can see is a blue circle.想象您需要進行銀行交易&#xff0c;但是網站是如此緩慢。 該頁面需要花費很多時間來加載&#xff0c;您只能看…

隱私策略_隱私圖標

隱私策略During its 2020 Worldwide Developers Conference, Apple spent time on one of today’s hottest topics — privacy. During the past couple of years, Apple has been rolling out various public campaigns aiming to position itself as a company that respect…

Java中的數組

一、數組的定義type[] arrayName;type arrayName[]; 推薦第一種 二、數組的初始化 含義&#xff1a;所謂的初始化&#xff0c;就是為數組的數組元素分配內存空間&#xff0c;并為每個數組元素賦初始值 &#xff08;1&#xff09;靜態初始化&#xff1a;arrayName new type[…

您一直在尋找5+個簡單的一線工具來提升Python可視化效果

Insightful and aesthetic visualizations don’t have to be a pain to create. This article will prevent 5 simple one-liners you can add to your code to increase its style and informational value.富有洞察力和美學的可視化不必費心創建。 本文將防止您添加到代碼中…