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 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 libaryimport pandas as pd# reading data from csvdf = 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:

这将是您的输出:

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] = 0matrix = matrix.values.tolist()

Here is your output, a much cleaner Chord Diagram:

这是您的输出,更清晰的和弦图:

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,

这是我的输出,

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 by Author
图片作者
# Just add the colors parameter and pass the value.Chord(matrix, names, colors="d3.schemeAccent").show()
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 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.taodudu.cc/news/show-995033.html

相关文章:

  • 最接近原点的 k 个点_第K个最接近原点的位置
  • 熊猫分发_熊猫新手:第二部分
  • 数据分析 绩效_如何在绩效改善中使用数据分析
  • 您一直在寻找5+个简单的一线工具来提升Python可视化效果
  • 产品观念:更好的捕鼠器_故事很重要:为什么您需要成为更好的讲故事的人
  • 面向Tableau开发人员的Python简要介绍(第2部分)
  • netflix_Netflix的计算因果推论
  • 高斯金字塔 拉普拉斯金字塔_金字塔学入门指南
  • 语言认知偏差_我们的认知偏差正在破坏患者的结果数据
  • python中定义数据结构_Python中的数据结构。
  • plotly django_使用Plotly为Django HTML页面进行漂亮的可视化
  • 软件工程方法学要素含义_日期时间数据的要素工程
  • 数据湖 data lake_在Data Lake中高效更新TB级数据的模式
  • ai对话机器人实现方案_显然地引入了AI —无代码机器学习解决方案
  • 图片中的暖色或冷色滤色片是否会带来更多点击? —机器学习A / B测试
  • 图卷积 节点分类_在节点分类任务上训练图卷积网络
  • 回归分析预测_使用回归分析预测心脏病。
  • aws spark_使用Spark构建AWS数据湖时的一些问题以及如何处理这些问题
  • 数据科学家编程能力需要多好_我们不需要这么多的数据科学家
  • sql优化技巧_使用这些查询优化技巧成为SQL向导
  • 物种分布模型_减少物种分布建模中的空间自相关
  • 清洁数据ploy n_清洁屋数据
  • 基于边缘计算的实时绩效_基于绩效的营销中的三大错误
  • 上凸包和下凸包_使用凸包聚类
  • 决策树有框架吗_决策框架
  • mysql那本书适合初学者_3本书适合初学者
  • 阎焱多少身价_2020年,数据科学家的身价是多少?
  • 卡尔曼滤波滤波方程_了解卡尔曼滤波器及其方程
  • 朴素贝叶斯分类器 文本分类_构建灾难响应的文本分类器
  • Seaborn:Python

python 交互式流程图_使用Python创建漂亮的交互式和弦图相关推荐

  1. python主程序流程图_用Python编程绘制流程图,你用过吗?

    您一定听说过 "Graphviz"绘图软件吧.Graphviz (Graph Visualization Software) 是一个由AT&T实验室启动的开源工具包,它采用 ...

  2. python做流程图_少儿Python编程_第十四讲:开发游戏

    无论哪一种编程语言,实现图形界面程序的方法都大同小异.本讲介绍用Python开发小游戏的方法,从中学习使用Python编写图形界面的程序,图形图像的基础知识,以及在图形界面程序中与用户交互.最后部分还 ...

  3. python 时间序列预测_使用Python进行动手时间序列预测

    python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...

  4. python 概率分布模型_使用python的概率模型进行公司估值

    python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...

  5. 使用python预测基金_使用python先知3 1创建预测

    使用python预测基金 This tutorial was created to democratize data science for business users (i.e., minimiz ...

  6. python 打印类型_让Python输出更漂亮:PrettyPrinter

    PrettyPrinter是Python 3.6 及以上版本中的一个功能强大.支持语法高亮.描述性的美化打印包.它使用了改进的Wadler-Leijen布局算法,和Haskell打印美化库中的pret ...

  7. python 网页编程_通过Python编程检索网页

    python 网页编程 The internet and the World Wide Web (WWW), is probably the most prominent source of info ...

  8. python dry原则_关于Python 的这几个技巧,你应该知道

    随着大数据时代的到来,我们每天都在接触爬虫相关的事情,这其中就不得不提及Python这门编程语言.我已经使用Python编程有多年了,即使今天我仍然惊奇于这种语言所能让代码表现出的整洁和对DRY编程原 ...

  9. python 创意项目_针对python开发人员的10个很棒的python项目创意

    python 创意项目 The joy of coding Python should be in seeing short, concise, readable classes that expre ...

最新文章

  1. python获取登录按钮_python爬虫24 | 搞事情了,用 Appium 爬取你的微信朋友圈。
  2. 使用VC实现一个“智能”自增减线程池
  3. 求表达式 f(n)结果末尾0的个数
  4. 计算机相关的考试题目,计算机考试相关题目汇总.doc
  5. js记录用户访问页面和停留时间
  6. SAP Spartacus的Angular.json内容一览
  7. python read()函数_Python File read()方法
  8. 《白鹿原》金句摘抄(六)
  9. CTS(4)---mtk cts FAIL处理方法
  10. 【registry】registry合并带spring boot项目第一弹
  11. shell 执行失败重试_Smart Retry主要是用来进行方法重试
  12. “成功”没那么有道理
  13. 【LeetCode】【数组】题号:73,矩阵置零
  14. [转载]架构指南 : Java1.7+Eclipse luna + Maven 3.2.5 +spring 4.1.4
  15. JavaScript高级知识点整理
  16. k近邻算法_k近邻算法
  17. window.name属性
  18. 什么是预付卡及预付卡发展前景
  19. 【UVM实战】第二章:一个简单的UVM验证平台(4)UVM 的终极大作:sequence
  20. linux中的怎么添加组,linux中添加用户 添加组

热门文章

  1. Linux平台上SQLite数据库教程(一)——终端使用篇
  2. C++ Primer
  3. 进程间同步(互斥量、信号量)
  4. dorado-SplitSpanel控件
  5. 验证部分表单是否重复
  6. PHP实现单击“添加”按钮增加一行表单项,并将所有内容插入到数据库中
  7. U-boot 打补丁,编译,设置环境变量,
  8. 从未有过的空闲学校生活
  9. c# nat udp转发
  10. 2.6 multimap