"""
在利用python进行画图时,我们可能常常用的颜色就是'k'黑色,'r'红色,'b'蓝色,'g'绿色等,这些颜色分别代表常见的
几种颜色。但是当我们画图比较多时,颜色如何分配呢?可以参考下面的这些方案。
这样在画图时,可以选用的就很多,当然在应用时,如果想让你的图更有对比性,可以将对比性差的
去掉不用。
下面的代码来自matplotlib官方。
====================
List of named colors
==================== This plots a list of the named colors supported in matplotlib. Note that
:ref:`xkcd colors <xkcd-colors>` are supported as well, but are not listed here
for brevity. For more information on colors in matplotlib see * the :doc:`/tutorials/colors/colors` tutorial;
* the `matplotlib.colors` API;
* the :doc:`/gallery/color/color_demo`.
""" from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors def plot_colortable(colors, title, sort_colors=True, emptycols=0): cell_width = 212
cell_height = 22
swatch_width = 48
margin = 12
topmargin = 40 # Sort colors by hue, saturation, value and name.
if sort_colors is True:
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(color))),
name)
for name, color in colors.items())
names = [name for hsv, name in by_hsv]
else:
names = list(colors) n = len(names)
print (n)
print (names)
ncols = 4 - emptycols
nrows = n // ncols + int(n % ncols > 0) width = cell_width * 4 + 2 * margin
height = cell_height * nrows + margin + topmargin
dpi = 72 fig, ax = plt.subplots(figsize=(width / dpi, height / dpi), dpi=dpi)
fig.subplots_adjust(margin/width, margin/height,
(width-margin)/width, (height-topmargin)/height)
ax.set_xlim(0, cell_width * 4)
ax.set_ylim(cell_height * (nrows-0.5), -cell_height/2.)
ax.yaxis.set_visible(False)
ax.xaxis.set_visible(False)
ax.set_axis_off()
ax.set_title(title, fontsize=24, loc="left", pad=10) for i, name in enumerate(names):
row = i % nrows
col = i // nrows
y = row * cell_height swatch_start_x = cell_width * col
text_pos_x = cell_width * col + swatch_width + 7 ax.text(text_pos_x, y, name, fontsize=14,
horizontalalignment='left',
verticalalignment='center') ax.add_patch(
Rectangle(xy=(swatch_start_x, y-9), width=swatch_width,
height=18, facecolor=colors[name], edgecolor='0.7')
) return fig plot_colortable(mcolors.BASE_COLORS, "Base Colors",
sort_colors=False, emptycols=1)
plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette",
sort_colors=False, emptycols=2) # sphinx_gallery_thumbnail_number = 3
plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") # Optionally plot the XKCD colors (Caution: will produce large figure)
# xkcd_fig = plot_colortable(mcolors.XKCD_COLORS, "XKCD Colors")
# xkcd_fig.savefig("XKCD_Colors.png") plt.show() #############################################################################
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.colors`
# - `matplotlib.colors.rgb_to_hsv`
# - `matplotlib.colors.to_rgba`
# - `matplotlib.figure.Figure.get_size_inches`
# - `matplotlib.figure.Figure.subplots_adjust`
# - `matplotlib.axes.Axes.text`
# - `matplotlib.patches.Rectangle`

  

opencv colors的更多相关文章

  1. OpenCV 人脸识别 C++实例代码

    #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include & ...

  2. 学习OpenCV——Surf(特征点篇)&flann

    Surf(Speed Up Robust Feature) Surf算法的原理                                                             ...

  3. OpenCV人脸检测demo--facedetect

    &1 问题来源 在运行官网的facedetect这个demo的时候,总是不会出来result的图形,电脑右下角提示的错误是“显示器驱动程序已停止响应,而且已恢复 windows 8(R)”. ...

  4. OpenCV图像Surf与flann特征点(转载)

    Surf(Speed Up Robust Feature) Surf算法的原理                                                             ...

  5. opencv 人脸识别 (一)训练样本的处理

    本文实现基于eigenface的人脸检测与识别.给定一个图像数据库,进行以下步骤: 进行人脸检测,将检测出的人脸存入数据库2 对数据库2进行人脸建模 在测试集上进行recognition   本篇实现 ...

  6. 《学习OpenCV》练习题第四章第八题ab

    这道题是利用OpenCV例子程序里自带的人脸检测程序,做点图像的复制操作以及alpha融合. 说明:人脸检测的程序我参照了网上现有的例子程序,没有用我用的OpenCV版本(2.4.5)的facedet ...

  7. opencv人脸检测分类器训练小结

    这两天在初学目标检测的算法及步骤,其中人脸检测作为最经典的算法,于是进行了重点研究.该算法最重要的是建立人脸检测分类器,因此我用了一天的时间来学习分类器的训练.这方面的资料很多,但是能按照一个资料运行 ...

  8. opencv 通过摄像头捕捉头部

    code: #include <opencv\cv.h> #include <opencv\highgui.h> #include <opencv\cxcore.h> ...

  9. 访问图像中的像素[OpenCV 笔记16]

    再更一发好久没更过的OpenCV,不过其实写到这个部分对计算机视觉算法有所了解的应该可以做到用什么查什么了,所以后面可能会更的慢一点吧,既然开了新坑,还是机器学习更有研究价值吧... 图像在内存中的存 ...

  10. 修改SR4000自带软件,支持opencv

      /*----------------------------------------------------------------------------- * * 版权声明: * 可以任意转载 ...

随机推荐

  1. sshd管理限制登录配置(centos7.9)

    背景情况:为了公网的主机,被无限的密码爆破,需要对主机的ssh进行安装加固 1.首先要禁用root的远程登录和修改ssh的端口 vi /etc/ssh/sshd_config# 修改端口,不适用22端 ...

  2. 3.2 逻辑设计和硬件控制语言HCL

    在硬件设计中,用电子电路来计算对位进行运算的函数,以及在各种存储器单元中存储位.大多数现代电路技术都是用信号线上的高电压或低电压来表示不同的位值.在当前的技术中,逻辑1是用1.0伏特左右的高电压表示的 ...

  3. git push origin master和git push的区别

    1.git push origin master 指定远程仓库名和分支名. 2.git push 不指定远程仓库名和分支名. 3. 这两者的区别:git push是git push origin ma ...

  4. leetcode简单(设计):[225, 232, 303, 703, 705, 706, 933, 1603, 1656, 09, 30, 041, 03.06]

    目录 225. 用队列实现栈(先入后出) 232. 用栈实现队列(先入先出) 303. 区域和检索 - 数组不可变 703. 数据流中的第 K 大元素 705. 设计哈希集合 706. 设计哈希映射 ...

  5. ComfyUI进阶:Comfyroll插件 (四)

    ComfyUI进阶:Comfyroll插件 (四) 前言: 学习ComfyUI是一场持久战,而Comfyroll 是一款功能强大的自定义节点集合,专为 ComfyUI 用户打造,旨在提供更加丰富和专业 ...

  6. Kotlin 字符串教程:深入理解与使用技巧

    Kotlin 字符串 字符串用于存储文本. 字符串包含由双引号包围的字符集合: 示例 var greeting = "Hello" 与 Java 不同,您不必指定变量是字符串.Ko ...

  7. 【DataBase】MySQL 12 SQL函数 聚合函数

    视频参考自:P53 - P58 https://www.bilibili.com/video/BV1xW411u7ax 什么是分组函数? 用来统计使用,其具体的实现都是基于对字段的值聚合再处理 又称为 ...

  8. 【EF Core】自动生成的字段值

    自动生成字段值,咱们首先想到的是主键列(带 IDENTITY 的主键).EF Core 默认的主键配置也是启用 Identity 自增长的,而且可以自动标识主键.前提是代表主键的实体属性名要符合以下规 ...

  9. 一直让 PHP 程序员懵逼的同步阻塞异步非阻塞,终于搞明白了

    大家好,我是码农先森. 经常听到身边写 Java.Go 的朋友提到程序异步.非阻塞.线程.协程,让系统性能提高到百万.千万并发,使我甚是惊讶属实羡慕.对于常年写 PHP 的我来说,最初听到这几个词时, ...

  10. 想不到WhaleStudio和Talend的差异竟如此之大!

    最近我们遇到很多客户需求是把Talend迁移到WhaleStudio,主要是发现WhaleStudio支持的数据源多很多,从各个版本的SAP到AWS Redshift,S3,从MangoDB CDC到 ...