当前位置:网站首页>matplotlib的cmap
matplotlib的cmap
2022-06-11 06:56:00 【煮酒cos】
plt.scatter(X[:, 0], X[:, 1], c=data_index, alpha=0.6, cmap=plt.cm.get_cmap('Set1', class_num))
在这里用到了cmap这个参数
matplotlib中用来做热图的颜色映射有很多种,我们可以选择各种不同的颜色映射来做出符合我们预期的热图。其源代码如下所示:
本代码是根据官网(http://matplotlib.org/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', 'inferno', 'plasma', 'magma']),
('Sequential', ['Blues', 'BuGn', 'BuPu',
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool',
'copper', 'gist_heat', 'gray', 'hot',
'pink', 'spring', 'summer', 'winter']),
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
'seismic']),
('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
'Pastel2', 'Set1', 'Set2', 'Set3']),
('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
'brg', 'CMRmap', 'cubehelix',
'gnuplot', 'gnuplot2', 'gist_ncar',
'nipy_spectral', 'jet', 'rainbow',
'gist_rainbow', 'hsv', 'flag', 'prism'])]
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):
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)
plt.show()
Perceptually Uniform Sequential、Sequential、Sequential (2)、Diverging、Qualitative、Miscellaneous对应的列表中的值均可作为cmap的值。
其效果图如下所示:





边栏推荐
- saltstack的常用模块
- Open source cartoon server mango
- 【概率论与数理统计】猴博士 笔记 p41-44 统计量相关小题、三大分布的判定、性质、总体服从正态分布的统计量小题
- 搜狐员工遭遇工资补助诈骗 黑产与灰产有何区别 又要如何溯源?
- 品牌定位个性六种形态及结论的重大意义
- Shell脚本之启动Nacos服务端
- Oracle prompt invalid number
- JS implementation of Hill sort of graphic insertion sort [with source code]
- Lazy load
- Reconstruction and preheating of linked list information management system (2) how to write the basic logic using linear discontinuous structure?
猜你喜欢

VTK-vtkPlane和vtkCutter使用

Open source cartoon server mango

【Matlab WSN通信】A_Star改进LEACH多跳传输协议【含源码 487期】

NPM upgrade: unable to load file c:\users\administrator\appdata\roaming\npm\npm-upgrade ps1

Flat design, blog website (VIII) code source code

Xunwei dry goods | Ruixin micro rk3568 development board TFTP & NFS writing (Part 1)

开源漫画服务器Mango

Zabbix 监控主机是否在线

socket. IO cross domain stepping pit

Difference between byte and bit
随机推荐
This comprehensive understanding
socket. IO cross domain stepping pit
Wan Zichang's article shows you promise
byte和bit的区别
Array de duplication....
Grayscale publishing through ingress
关于 QtCreator的设计器QtDesigner完全无法正常拽托控件 的解决方法
UEFI finding PCI devices
Object. Specific implementation and difference between create() and new
Simple integration of client go gin six list watch two (about the improvement of RS, pod and deployment)
通过 Ingress 进行灰度发布
About parseint()
arguments......
About daily report plan
Pytest自动化测试-简易入门教程(01)
Starting from scratch (I)
Use of qscriptengine class
微信小程序开发(原生和uniapp)DOM标签对比介绍
Exchange two values without introducing the third variable
[MATLAB image fusion] particle swarm optimization adaptive multispectral image fusion [including source code phase 004]