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.mzph.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 …

Viewport3D 类Viewport3D 类Viewport3D 类

.NET Framework 类库Viewport3D 类更新&#xff1a;2007 年 11 月为三维可视内容提供呈现图面。命名空间&#xff1a; System.Windows.Controls程序集&#xff1a; PresentationFramework&#xff08;在 PresentationFramework.dll 中&#xff09;用于 XAML 的 XMLNS&#xf…

网络浏览器如何工作

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…

基于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…

您一直在寻找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.富有洞察力和美学的可视化不必费心创建。 本文将防止您添加到代码中…

figma 安装插件_彩色滤光片Figma插件,用于色盲

figma 安装插件So as a UX Designer, it is important to design with disabilities in mind. One of these is color blindness. It is important to make sure important information on your product is legible to everyone. This is why I like using this tool:因此&…

产品观念:更好的捕鼠器_故事很重要:为什么您需要成为更好的讲故事的人

产品观念&#xff1a;更好的捕鼠器重点 (Top highlight)Telling a compelling story helps you get your point across effectively else you get lost in translation.讲一个引人入胜的故事可以帮助您有效地传达观点&#xff0c;否则您会迷失在翻译中。 Great stories happen…

7月15号day7总结

今天复习了springMVC的框架搭建。 思维导图&#xff1a; 转载于:https://www.cnblogs.com/kangy123/p/9315919.html

设计师的10种范式转变

For $250, a business can pay a graphic designer to create a logo for their business. Or, for $10,000 a business can hire a graphic designer to form a design strategy that contextually places the business’s branding in a stronghold against the market it’s…

面向Tableau开发人员的Python简要介绍(第2部分)

用PYTHON探索数据 (EXPLORING DATA WITH PYTHON) And we’re back! Let’s pick up where we left off in the first article of this series and use the visual we built there as a starting point.我们回来了&#xff01; 让我们从在本系列的第一篇文章中停下来的地方开始&…

设计组合中的10个严重错误可能会导致您丧命

As an agency co-founder and design lead, I’ve been participating in many recruitment processes. I’ve seen hundreds of portfolios and CVs of aspiring designers. If you’re applying for a UI designer position, it is good to have some things in mind and to …