python matplotlib seaborn中的camp 、colormap(颜色映射) 色阶 配色 选择,翻转颜色

python matplotlib seaborn中的camp 、colormap(颜色映射) 色阶 配色 选择,翻转颜色

原创

已于 2023-04-13 10:31:12 修改

·

1.9w 阅读

·

28

·

104

·

CC 4.0 BY-SA版权

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

文章标签:

#matplotlib

#python

#开发语言

于 2021-04-02 15:42:32 首次发布

画图

专栏收录该内容

28 篇文章

订阅专栏

本文介绍了如何在Python的Matplotlib和Seaborn库中选择和反转颜色映射。展示了各种颜色分类,如连续、离散、感知均匀等,并提供了详细的代码示例,帮助用户根据需要选择合适的颜色梯度。同时,还提到了官方参考链接以供进一步探索。

本文章已经生成可运行项目,一键运行

python matplotlib seaborn camp 色阶 配色 选择,翻转颜色

官方参考:翻转颜色辅助选择

官方参考:

https://matplotlib.org/2.0.2/examples/color/colormaps_reference.html. 绘制过程

import numpy as np

import matplotlib.pyplot as plt

# Have colormaps separated into categories:

# http://matplotlib.org/examples/color/colormaps_reference.html

cmaps = [('Perceptually Uniform Sequential', [

'viridis', 'plasma', 'inferno', 'magma']),

('Sequential', [

'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',

'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',

'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']),

('Sequential (2)', [

'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink',

'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia',

'hot', 'afmhot', 'gist_heat', 'copper']),

('Diverging', [

'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',

'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']),

('Qualitative', [

'Pastel1', 'Pastel2', 'Paired', 'Accent',

'Dark2', 'Set1', 'Set2', 'Set3',

'tab10', 'tab20', 'tab20b', 'tab20c']),

('Miscellaneous', [

'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern',

'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv',

'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])]

nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)

gradient = np.linspace(0, 1, 256)

gradient = np.vstack((gradient, gradient))

def plot_color_gradients(cmap_category, cmap_list, nrows):

fig, axes = plt.subplots(nrows=nrows)

fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)

axes[0].set_title(cmap_category + ' colormaps', fontsize=14)

for ax, name in zip(axes, cmap_list):

ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))

pos = list(ax.get_position().bounds)

x_text = pos[0] - 0.01

y_text = pos[1] + pos[3]/2.

fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

# Turn off *all* ticks & spines, not just the ones with colormaps.

for ax in axes:

ax.set_axis_off()

for cmap_category, cmap_list in cmaps:

plot_color_gradients(cmap_category, cmap_list, nrows)

plt.show()

翻转颜色

只需要在选择的后面加 ‘_r’ 即可

# 聚类热图

sns.clustermap( plot_df,

row_cluster=False, # 行 聚类

col_cluster=True, # 列 聚类

cmap='viridis_r', # 颜色配置

)

辅助选择

https://matplotlib.org/2.0.2/users/colormaps.html

本文已生成可运行项目一键运行

生成项目


世上动物如此多,为何只有兔子能进月亮陪伴嫦娥?
公司法人变更需要多久