seaborn.mpl_palette

译者:Modrisco

seaborn.mpl_palette(name, n_colors=6)

从一个 matplotlib 调色板中返回离散颜色。

请注意,这会正确处理定性的 colorbrewer 调色板,但如果您要求的颜色多于特定的定性调色板,提供的颜色将会比您预期的少。相反,使用 color_palette() 函数请求一个定性 colorbrewer 调色板将会返回预期数目的颜色,但是是循环型的。

如果您在使用 IPython notebook,您还可以通过 choose_colorbrewer_palette() 函数交互式选择调色板。

参数:name:string

调色板名字,应该是一个被命名的 matplotlib colormap。

n_colors:int

调色板中离散颜色的个数。

返回值:palette or cmap:seaborn 调色板或者 matplotlib colormap

类似列表的颜色对象的 RGB 元组,或者可以将连续值映射到颜色的 colormap 对象,具体取决于 as_cmap 参数的值。

例子

生成一个含有 8 种颜色的定性 colorbrewer 调色板:

>>> import seaborn as sns; sns.set()
>>> sns.palplot(sns.mpl_palette("Set2", 8))

http://seaborn.pydata.org/_images/seaborn-mpl_palette-1.png

生成一个连续的 colorbrewer 调色板:

>>> sns.palplot(sns.mpl_palette("Blues"))

http://seaborn.pydata.org/_images/seaborn-mpl_palette-2.png

生成一个发散调色板:

>>> sns.palplot(sns.mpl_palette("seismic", 8))

http://seaborn.pydata.org/_images/seaborn-mpl_palette-3.png

生成一个 “dark” 顺序调色板:

>>> sns.palplot(sns.mpl_palette("GnBu_d"))

http://seaborn.pydata.org/_images/seaborn-mpl_palette-4.png


书籍推荐