定义python的色条_定义自定义seaborn调色板?

Matplotlib提供tab20颜色映射,这可能适合这里。在

你也可以从一个现有的颜色图和随机化他们的顺序。在

有两种工具可以获得n种不同颜色的列表

比较这三种选择:import numpy as np

import matplotlib.pyplot as plt

plt.rcParams["axes.xmargin"] = 0

plt.rcParams["axes.ymargin"] = 0

# Take the colors of an existing categorical map

colors1 = plt.cm.tab20.colors

# Take the randomized colors of a continuous map

inx = np.linspace(0,1,20)

np.random.shuffle(inx)

colors2 = plt.cm.nipy_spectral(inx)

# Take a list of custom colors

colors3 = ["#9d6d00", "#903ee0", "#11dc79", "#f568ff", "#419500", "#013fb0",

"#f2b64c", "#007ae4", "#ff905a", "#33d3e3", "#9e003a", "#019085",

"#950065", "#afc98f", "#ff9bfa", "#83221d", "#01668a", "#ff7c7c",

"#643561", "#75608a"]

fig = plt.figure()

x = np.arange(10)

y = np.random.rand(20, 10)+0.2

y /= y.sum(axis=0)

for i, colors in enumerate([colors1, colors2, colors3]):

with plt.style.context({"axes.prop_cycle" : plt.cycler("color", colors)}):

ax = fig.add_subplot(1,3,i+1)

ax.stackplot(x,y)

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值