一、说明
基于milkviz库,使用matplotlib的savefig接口保存为svg矢量格式,以下为生成效果。
二、安装
milkviz库是针对matplotlib的二次封装,以下官网基本示例,可快速生成以下数据类型图:
使用pip安装即可:
pip install milkviz
三、源代码
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File : plot_dot_heatmap.py
@Time : 2022/12/05 10:39:32
@Author : KmBase
@Version : 1.0
@License : (C)Copyright 1984-2022, KmBase
@Desc : None
'''
"""
Dot heatmap Example
======================
Here shows how to draw dot heatmap
"""
import numpy as np
import milkviz as mv
from matplotlib import pyplot as plt
np.random.seed(0)
shape = (15, 15)
colors = np.random.randint(1, 100, shape)
sizes = np.random.randint(1, 100, shape)
matrix = np.random.randint(1, 100, shape)
labels = [
"Apple", "Avocado", "Banana", "Blueberries", "Coconut", "Kiwifruit",
"Lemon", "Mango", "Olives", "Papaya", "Persimmon", "Plum", "Quince",
"Soursop", "Watermelon"
]
mv.dot_heatmap(sizes,
colors,
matrix,
xticklabels=labels,
dot_size_legend_kw={"title": "Dot Size"},
dot_hue_cbar_kw={"title": "Dot Color"},
matrix_cbar_kw={"title": "Matrix Color"})
plt.tight_layout()
plt.savefig('./0.svg')
plt.show()