Changelog:
- **29 June 2020** - Optimisation and bug fixes to the tooltip have massively improved the interactive performance of the visualisation (**Rebuild your chord diagrams** to take advantage of this change).
- **22 May 2020** - Optimisation and bug fixes have massively improved the interactive performance of the visualisation (**Rebuild your chord diagrams** to take advantage of this change).
- **21 May 2020** - Please update to the latest version of `chord`. Backwards compatability has been introduced, so from this version onwards, new versions won't break older ones!
![Example Image](images/2.gif)
# Introduction
In a chord diagram (or radial network), entities are arranged radially as segments with their relationships visualised by arcs that connect them. The size of the segments illustrates the numerical proportions, whilst the size of the arc illustrates the significance of the relationships<sup id="fnref-footnote"><a class="footnote-ref" href="#fn-footnote">1</a></sup>.
Chord diagrams are useful when trying to convey relationships between different entities, and they can be beautiful and eye-catching.
# The Chord Package
I wanted to do a section on Chord Diagrams for my book, [Data Is Beautiful](https://store.shahinrostami.com/product/data-is-beautiful/).
With Python in mind, there are many libraries available for creating Chord diagrams, such as [Plotly](https://plotly.com/python/v3/filled-chord-diagram/), [Bokeh](http://docs.bokeh.org/en/0.12.0/docs/gallery/chord_chart.html), and a few that are lesser-known. However, I wanted to use the implementation from [d3](https://observablehq.com/@d3/chord-diagram?collection=@d3/d3-chord) because it can be customised to be highly interactive and to look beautiful.
I couldn't find anything that ticked all the boxes, [so I made](https://pypi.org/project/chord/) a wrapper around d3-chord myself. It took some time to get it working, but I wanted to hide away everything behind a single constructor and method call. The tricky part was enabling multiple chord diagrams on the same page, and then loading resources in a way that would support Jupyter Lab.
The primary support is for `Jupyter Lab` (not the older `Jupyter Notebook`).
# Installation
Available on https://pypi.org/project/chord/ through `pip`:
```bash
pip install chord
```
# Usage
## Python
## Python (HTML file)
```python
Chord(matrix, names).to_html()
```
## Jupyter Lab (Notebook)
```python
Chord(matrix, names).show()
```
## Defaults
```python
Chord(self,
matrix,
names,
colors="d3.schemeSet1",
opacity=0.8,
padding=0.01,
width=700,
label_color="#454545",
wrap_labels=True,
margin=0,
credit=False,
)
```
# Examples
You can see the actual interactive examples [on this page](https://shahinrostami.com/posts/statistics/data-is-beautiful/chord-diagrams/). The below examples are screenshots.
## The Dataset
The focus for this section will be the demonstration of the `chord` package. To keep it simple, we will use synthetic data that illustrates the co-occurrences between movie genres within the same movie.
```python
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]
names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]
```
## Default Settings
Let's see what the `Chord()` defaults produce when we invoke the `show()` method.
```python
Chord(matrix, names).show()
```
![Example Image](images/1.png)
You can also save it to a HTML file.
```python
Chord(matrix, names).to_html()
```
## Different Colours
The defaults are nice, but what if we want different colours? You can pass in almost anything from [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic#categorical), or you could pass in a list of hexadecimal colour codes.
```python
Chord(matrix, names, colors="d3.schemeSet2").show()
```
![Example Image](images/2.png)
```python
Chord(matrix, names, colors=f"d3.schemeGnBu[{len(names)}]").show()
```
![Example Image](images/3.png)
```python
Chord(matrix, names, colors="d3.schemeSet3").show()
```
![Example Image](images/4.png)
```python
Chord(matrix, names, colors=f"d3.schemePuRd[{len(names)}]").show()
```
![Example Image](images/5.png)
```python
Chord(matrix, names, colors=f"d3.schemeYlGnBu[{len(names)}]").show()
```
![Example Image](images/6.png)
```python
hex_colours = ["#222222", "#333333", "#4c4c4c", "#666666", "#848484", "#9a9a9a"]
Chord(matrix, names, colors=hex_colours).show()
```
![Example Image](images/7.png)
## Label Styling
We can disable the wrapped labels, and even change the colour.
```python
Chord(matrix, names, wrap_labels=False, label_color="#4c40bf").show()
```
![Example Image](images/8.png)
## Opacity
We can also change the default opacity of the relationships.
```python
Chord(matrix, names, opacity=0.1).show()
```
![Example Image](images/9.png)
# Diagram Size
We can change the maximum diagram size by specifying a width.
```python
Chord(matrix, names, width=400).show()
```
We can change the padding between chord segments by specifying the padding.
```python
Chord(matrix, names, padding=0.3).show()
```
<div class="footnote">
<hr>
<ol>
<li id="fn-footnote">
<p>Tintarev, N., Rostami, S., & Smyth, B. (2018, April). Knowing the unknown: visualising consumption blind-spots in recommender systems. In Proceedings of the 33rd Annual ACM Symposium on Applied Computing (pp. 1396-1399). <a class="footnote-backref" href="#fnref-footnote" title="Jump back to footnote 1 in the text">↩</a></p>
</li>
</ol>
</div>
# Credits
- d3-chord, Mike Bostock.
- d3-chord gradient fills, Nadieh Bremer.
- `chord` (Python), Shahin Rostami.
![Example Image](images/1.gif)
```
```
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
chord-0.0.16.tar.gz (11个子文件)
chord-0.0.16
PKG-INFO 8KB
chord.egg-info
PKG-INFO 8KB
requires.txt 10B
not-zip-safe 1B
SOURCES.txt 208B
top_level.txt 6B
dependency_links.txt 1B
setup.cfg 38B
setup.py 521B
chord
__init__.py 6KB
README.md 6KB
共 11 条
- 1
资源评论
- Nicolezk2022-07-08资源值得借鉴的内容很多,那就浅学一下吧,值得下载!
挣扎的蓝藻
- 粉丝: 12w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- 基于JSP毕业设计-基于WEB操作系统课程教学网站的设计与实现(源代码+论文).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功