Seaborn.choose_colorbrewer_palette() 方法
Seaborn.chooose_colorbrewer_palette() 方法是一个调色板小部件,它使用户能够选择给定选项中存在的颜色。 这是使用户能够选择颜色的非常有用且创造性的方式。
这些调色板是内置的 matplotlib 调色板,可以在许多 seaborn 函数中通过名称访问它们。 它们也可以通过传递此函数返回的对象来使用。
语法
以下是 choose_colorbrewer_palette() 的语法 −
seaborn.choose_colorbrewer_palette(data_type, as_cmap=False)
参数
该方法的参数如下所示。
S.No | 参数及说明 |
---|---|
1 | Datatype 从定性、发散和顺序中获取值。 您想要可视化的数据类型由此描述。 你应该知道你可以传递子字符串,比如 'q' 代表 'qualitative. |
2 | As_cmap 此可选参数采用布尔值,如果为 true,则返回 matplotlib 颜色图。 |
返回值
此方法返回一个 pal 或 cmap,它是颜色列表或 matplotlib 颜色图。 可以在下面给出的示例中理解该方法。
示例 1
在这个例子中,我们将看到顺序数据类型如何工作以及它提供的所有选项。 以下代码行可用于使用顺序调色板小部件。
sns.choose_colorbrewer_palette("sequential", as_cmap=False)
输出
输出结果如下 −

可用的不同名称是 −

可用的不同变体是 −

反向会将颜色顺序从深色变为浅色,反之亦然,而深色会将颜色从浅色变为深色。
示例 2
在此示例中,我们将了解发散数据块的工作原理及其提供的所有选项。 以下代码行可用于使用顺序调色板小部件。
sns.choose_colorbrewer_palette("diverging", as_cmap=False)
输出
输出结果如下 −

可用的不同名称是 −

可用的不同变体是 −

反向会将颜色顺序从深色变为浅色,反之亦然,常规是正常顺序。
示例 3
在此示例中,我们将了解定性数据图块的工作原理及其提供的所有选项。 以下代码行可用于使用顺序调色板小部件。
sns.choose_colorbrewer_palette("qualitative", as_cmap=False)
输出
输出如下,

可用的不同名称是,

在所有这些示例中,n 表示要在颜色图中显示的颜色数量,数据集是颜色的去饱和度。