又一个配色新工具,颜色盘多达2500+类!
好看的配色,不仅能让图表突出主要信息,更能吸引读者。
本次再分享一个配色工具pypalettes,颜色盘多达2500+类,三行代码使用。
安装pypalettes
pip install pypalettes
pypalettes使用
第1步,挑选颜色盘
比如,挑选了'hornets'颜色盘,包含三种颜色。
第2步,颜色盘传给任意可视化工具
以可视化工具seaborn为例子,seaborn可接受ListedColormap、RGB、HEX等种类颜色,pypalettes中包含对应的转化方法。
from pypalettes import load_cmapcmap = load_cmap('hornets') # load_cmap导入'hornets'颜色盘
cmap
cmap.colors #转换为seaborn可接受的ListedColormap list格式
from pypalettes import get_rgbget_rgb('hornets') #get_rgb转换为RGB色号
from pypalettes import get_hexget_hex('hornets') #get_hex转换为HEX色号
在任何支持ListedColormap、RGB、HEX等格式颜色号的软件中,即可使用pypalettes中的'hornets'颜色盘。
pypalettes使用案例
以Python seaborn中使用pypalettes为例。
hornets颜色盘
import matplotlib.pyplot as plt
import palettablefrom pypalettes import load_cmap
cmap = load_cmap('hornets') #导入pypalettes中的'hornets'颜色盘
f, axs = plt.subplots(ncols=2,
figsize=(8, 4),
gridspec_kw=dict(width_ratios=[4, 3]))
sns.scatterplot(
data=penguins,
x="喙深 (毫米)",
y="喙长 (毫米)",
#使用'hornets'颜色盘
palette=cmap.colors, #使用'hornets'转换为ListedColormap格式的颜色号
s=300,
alpha=0.7,
hue="企鹅的种类",
ax=axs[0])
sns.histplot(
data=penguins,
x="企鹅的种类",
hue="企鹅的种类",
#使用'hornets'颜色盘
palette=cmap.colors,
shrink=.8,
alpha=.7,
legend=False,
ax=axs[1])
f.tight_layout()
knicks_retro颜色盘
import matplotlib.pyplot as plt
import palettablefrom pypalettes import load_cmap
cmap = load_cmap('knicks_retro')
f, axs = plt.subplots(ncols=2,
figsize=(8, 4),
gridspec_kw=dict(width_ratios=[4, 3]))
sns.scatterplot(
data=penguins,
x="喙深 (毫米)",
y="喙长 (毫米)",
#使用'knicks_retro'颜色盘
palette=cmap.colors,
s=300,
alpha=0.7,
hue="企鹅的种类",
ax=axs[0])
sns.histplot(
data=penguins,
x="企鹅的种类",
hue="企鹅的种类",
#使用'knicks_retro'颜色盘
palette=cmap.colors,
shrink=.8,
alpha=.7,
legend=False,
ax=axs[1])
f.tight_layout()
pelicans颜色盘
import matplotlib.pyplot as plt
import palettablefrom pypalettes import load_cmap
cmap = load_cmap('pelicans')
f, axs = plt.subplots(ncols=2,
figsize=(8, 4),
gridspec_kw=dict(width_ratios=[4, 3]))
sns.scatterplot(
data=penguins,
x="喙深 (毫米)",
y="喙长 (毫米)",
#使用'pelicans'颜色盘
palette=cmap.colors,
s=300,
alpha=0.7,
hue="企鹅的种类",
ax=axs[0])
sns.histplot(
data=penguins,
x="企鹅的种类",
hue="企鹅的种类",
#使用'pelicans'颜色盘
palette=cmap.colors,
shrink=.8,
alpha=.7,
legend=False,
ax=axs[1])
f.tight_layout()
参考:https://github.com/JosephBARBIERDARNAL/pypalettes
-END-
每类图表包含详细代码+详细代码注释,多达8000行代码,例如,
如何加入学习?
👇(收费、务必备注:169)
✅解锁获取6大权限:
代码(复制即可运行) 在线教程文档(方便后续更新) 依赖数据(免费下载) 微信交流群 后续更新 交流群定期包邮送最新统计、编程、AI类书籍