直接定义一个类来获取cmap中各个颜色方便使用:

使用的话:mycolor = MyColor(‘Accent’); mycolor.get_color();# 每次就调用获取下一个cmap中的颜色。

class MyColor(object):def __init__(self, cmap_name):self.color_set  = plt.get_cmap(cmap_name).colorsself.idx = 0self.color_len = len(self.color_set)def get_color(self):if self.idx == self.color_len - 1:self.idx = 0color = self.color_set[self.idx]self.idx += 1return color

可视化官方提供的cmap

比如查看:[‘Pastel1’, ‘Pastel2’, ‘Paired’, ‘Accent’, ‘Dark2’, ‘Set1’, ‘Set2’, ‘Set3’, ‘tab10’, ‘tab20’, ‘tab20b’, ‘tab20c’]

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as pltcmaps = {}
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))def plot_color_gradients(category, cmap_list):# Create figure and adjust figure height to number of colormapsnrows = len(cmap_list)figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh), dpi=100)fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh,left=0.2, right=0.99)axs[0].set_title(f'{category} colormaps', fontsize=14)for ax, name in zip(axs, cmap_list):ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10,transform=ax.transAxes)# Turn off *all* ticks & spines, not just the ones with colormaps.for ax in axs:ax.set_axis_off()# Save colormap list for later.cmaps[category] = cmap_listplot_color_gradients('Qualitative',['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2','Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b','tab20c'])

运行后:

matplotlib cmap取值相关推荐

  1. python画图,使用matplotlib和seaborn来设置图形的字体大小,坐标轴的线宽,风格,取值范围

    1. matplotlib 样式的设计 1.1 设置坐标轴的线框 如果我们要设置坐标轴的线宽,我们可以向下面这样做: import matplotlib.pyplot as plt###设置坐标轴的粗 ...

  2. scatter python cmap_Matplotlib.pyplot.scatter()中颜色映射cmap的可能取值

    颜色映射cmap可能的取值: Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, C ...

  3. numpy在折线图上添加取值_见识matplotlib:不常见的一面,折线图

    江湖上所公认的一句话,字不如表,表不如图!人们往往都更喜欢看图说话,那么用python的各位大侠们,大家都在用什么画图呢?各种各样的画图包犹如各式各样的兵器,有的兵器功能单一但是在细分领域超级专业无敌 ...

  4. 机器学习——时间序列ARIMA模型(四):自相关函数ACF和偏自相关函数PACF用于判断ARIMA模型中p、q参数取值

    文章目录 1.自相关函数ACF 2.偏自相关函数PACF 3.ARIMA(p,d,q)的阶数判断 4.代码实现 1.引入所需依赖 2.数据读取与处理 3.一阶差分与绘图 4.ACF 5.PACF 1. ...

  5. C++ 获取内存地址(取值运算符)

    c++ 获取内存地址使用取值运算符 : & 下面看下& 的使用 #include <iostream> using namespace std; int main() {s ...

  6. python几种数据类型的取值方式

    今天我们主要来学习下python的几种数据类型的取值方式! 首先我们先来看下python的几种数据类型,python有五个标准的数据类型: number(数字) string(字符串) list(列表 ...

  7. C++ 笔记(14)— 指针(指针声明、取地址、取值、new/delete、NULL指针、指针运算、指针数组、数组指针、指针传递给函数、从函数返回指针)

    1. 声明指针 指针是一个变量,其值为另一个变量的地址,即,内存位置的直接地址.就像其他变量或常量一样,您必须在使用指 针存储其他变量地址之前,对其进行声明. 指针变量声明的一般形式为: type * ...

  8. dateTimePicker编辑状态下,取值不正确的问题

    当对dateTimePicker进行编辑,回车,调用函数处理dateTimePicker的value值时,其取值结果是你编辑之前的值,而不是你编辑后的值,虽然dateTimePicker.text的值 ...

  9. python嵌套字典取值_python嵌套字典比较值与取值的实现示例

    python嵌套字典比较值与取值的实现示例 本文通过示例给大家介绍了python嵌套字典比较值,取值,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧. 示例代码 #取值import t ...

最新文章

  1. Spring MVC配置文件的三个常用配置详解
  2. WP7多国语言支持 from:http://blog.csdn.net/lee353086/article/details/6260676
  3. (转)c3p0配置大全
  4. 2007年10月小记
  5. python窗口显示表格_pyqt 调用tablewidget窗口时无法显示窗口内容
  6. mysql sql 去除重复行_mysql – sql自连接表删除重复行
  7. TypeError: can't pickle _thread.RLock objects
  8. Apache Spark 2.2.0 中文文档 - Spark RDD(Resilient Distributed Datasets)
  9. resharper 7.x 注册码key
  10. 铁路联网售票系统 按计算机应用,铁路联网售票系统按计算机应用的分类它属于...
  11. python免安装版使用
  12. 视觉SLAM十四讲 第7讲 (3) 相机运动估计 2D-2D/3D-2D/3D-3D
  13. mybatis where 标签使用
  14. SQLSTATE=08S01通讯连接失败
  15. ubuntu项目移植windows
  16. java机试题---2021(算法)
  17. ChatGPT自动写了个AI办公office word插件,低配copilot,程序员看了焦虑。
  18. 规范升级 NPM 包
  19. kali系统---DNS收集分析之dnsrecon
  20. 这应该是我见过最好的机房监控解决方案了!

热门文章

  1. U盘安装Win Server 2008
  2. (转载)计算机视觉当中的专业英语
  3. PC上测试移动端网站和模拟手机浏览器
  4. 安防无战事:一场10213亿元的误会
  5. 3GPP TS 29244-g30 中英文对照 | 5.11 User plane inactivity detection and reporting
  6. 安卓系统怎么模拟java_电脑上安装安卓系统模拟器的方法(直接用JAVA虚拟成手机)...
  7. excel 批量生成条码
  8. jeecgboot功能优化——前端表格换行与不换行
  9. 如何计算对数收益率和净值化转换
  10. MySQL完美卸载-奇怪的小知识