Python 定义自定义seaborn调色板?

Python 定义自定义seaborn调色板?,python,matplotlib,plot,seaborn,color-palette,Python,Matplotlib,Plot,Seaborn,Color Palette,我正在尝试构建一个调色板来消除大量堆叠条的歧义。当我使用任何离散调色板(例如静音)时,颜色会重复,当我使用任何连续颜色贴图(例如立方体贴图)时,颜色会一起运行 使用静音: 使用cubehelix: 我需要一个调色板包含大量不同的非连续颜色。我认为这可以通过使用现有的连续调色板并排列颜色来实现,但我不知道如何做到这一点,尽管谷歌搜索了很多次,但我仍然无法确定如何定义自定义调色板 非常感谢您的帮助。Matplotlib提供了tab20颜色映射,可能适合这里使用 此外,您还可以从现有的颜色映射中获

我正在尝试构建一个调色板来消除大量堆叠条的歧义。当我使用任何离散调色板(例如
静音
)时,颜色会重复,当我使用任何连续颜色贴图(例如
立方体贴图
)时,颜色会一起运行

使用
静音

使用
cubehelix

我需要一个调色板包含大量不同的非连续颜色。我认为这可以通过使用现有的连续调色板并排列颜色来实现,但我不知道如何做到这一点,尽管谷歌搜索了很多次,但我仍然无法确定如何定义自定义调色板


非常感谢您的帮助。

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()

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()

你见过:,你见过:,和吗