python数据可视化桑基图
时间: 2023-09-02 19:08:35 浏览: 198
Python数据可视化中的桑基图是一种用于展示流动关系的图表。通过使用matplotlib库中的Sankey类,可以创建一个桑基图对象,然后通过add()方法添加数据和配置选项,最后使用finish()方法完成桑基图的绘制。
在绘制桑基图时,可以设置流动的收入和支出数据,每个流动的标签,以及流动的方向。可以通过设置边缘线条颜色、填充颜色、透明度和图表中心的标签等来美化桑基图。
示例代码如下:
```python
import matplotlib.pyplot as plt
from matplotlib.sankey import Sankey
flows = [0.7, 0.3, -0.3, -0.1, -0.3, -0.1, -0.1, -0.1]
labels = ["工资", "副业", "生活", "购物", "深造", "运动", "其他", "买书"]
orientations = [1, 1, 0, -1, 1, -1, 1, 0]
sankey = Sankey()
sankey.add(flows=flows, labels=labels, orientations=orientations, color="black", fc="lightgreen", patchlabel="生活消费", alpha=0.7)
diagrams = sankey.finish()
diagrams<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Python培训之可视化技术:桑基图怎么做?](https://blog.csdn.net/zy1992As/article/details/125275056)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [Python数据可视化 Pyecharts 制作 Sankey 桑基图](https://blog.csdn.net/qq_20288327/article/details/115696467)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文