设置颜色条

对于图形中由彩色的点、线、面构成的连续标签,用颜色条来表示的效果比较好,在Matplotlib中,颜色条是一个独立的坐标轴。

可视图形的颜色选择可参考matplotlib配色方案。

Choosing Colormaps — Matplotlib 1.4.1 documentation

重点关注的配色方案

  • 顺序配色方案:由一组连续的颜色构成的配色方案(例如binary 或 viridis)。
  • 互逆配色方案:通常有两种互补的颜色构成,表示正反两种含义(例如RdBu 或 PuOr)
  • 定性配色方案:随机顺序的一组颜色(例如rainbow 或 jet)
plt.imshow(
X,
cmap=None,
norm=None,
aspect=None,
interpolation=None,
alpha=None,
vmin=None,
vmax=None,
origin=None,
extent=None,
shape=<deprecated parameter>,
filternorm=1,
filterrad=4.0,
imlim=<deprecated parameter>,
resample=None,
url=None,
*,
data=None,
**kwargs,
)
Docstring:
Display an image, i.e. data on a 2D regular raster. Parameters
----------
X : array-like or PIL image
The image data. Supported array shapes are: - (M, N): an image with scalar data. The data is visualized
using a colormap.
- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).
- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),
i.e. including transparency. The first two dimensions (M, N) define the rows and columns of
the image. Out-of-range RGB(A) values are clipped. cmap : str or `~matplotlib.colors.Colormap`, optional
The Colormap instance or registered colormap name used to map
scalar data to colors. This parameter is ignored for RGB(A) data.
Defaults to :rc:`image.cmap`. norm : `~matplotlib.colors.Normalize`, optional
The `Normalize` instance used to scale scalar data to the [0, 1]
range before mapping to colors using *cmap*. By default, a linear
scaling mapping the lowest value to 0 and the highest to 1 is used.
This parameter is ignored for RGB(A) data. aspect : {'equal', 'auto'} or float, optional
Controls the aspect ratio of the axes. The aspect is of particular
relevance for images since it may distort the image, i.e. pixel
will not be square. This parameter is a shortcut for explicitly calling
`.Axes.set_aspect`. See there for further details. - 'equal': Ensures an aspect ratio of 1. Pixels will be square
(unless pixel sizes are explicitly made non-square in data
coordinates using *extent*).
- 'auto': The axes is kept fixed and the aspect is adjusted so
that the data fit in the axes. In general, this will result in
non-square pixels. If not given, use :rc:`image.aspect` (default: 'equal'). interpolation : str, optional
The interpolation method used. If *None*
:rc:`image.interpolation` is used, which defaults to 'nearest'. Supported values are 'none', 'nearest', 'bilinear', 'bicubic',
'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser',
'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc',
'lanczos'. If *interpolation* is 'none', then no interpolation is performed
on the Agg, ps, pdf and svg backends. Other backends will fall back
to 'nearest'. Note that most SVG renders perform interpolation at
rendering and that the default interpolation method they implement
may differ. See
:doc:`/gallery/images_contours_and_fields/interpolation_methods`
for an overview of the supported interpolation methods. Some interpolation methods require an additional radius parameter,
which can be set by *filterrad*. Additionally, the antigrain image
resize filter is controlled by the parameter *filternorm*. alpha : scalar, optional
The alpha blending value, between 0 (transparent) and 1 (opaque).
This parameter is ignored for RGBA input data. vmin, vmax : scalar, optional
When using scalar data and no explicit *norm*, *vmin* and *vmax*
define the data range that the colormap covers. By default,
the colormap covers the complete value range of the supplied
data. *vmin*, *vmax* are ignored if the *norm* parameter is used. origin : {'upper', 'lower'}, optional
Place the [0,0] index of the array in the upper left or lower left
corner of the axes. The convention 'upper' is typically used for
matrices and images.
If not given, :rc:`image.origin` is used, defaulting to 'upper'. Note that the vertical axes points upward for 'lower'
but downward for 'upper'. See the :doc:`/tutorials/intermediate/imshow_extent` tutorial for
examples and a more detailed description. extent : scalars (left, right, bottom, top), optional
The bounding box in data coordinates that the image will fill.
The image is stretched individually along x and y to fill the box. The default extent is determined by the following conditions.
Pixels have unit size in data coordinates. Their centers are on
integer coordinates, and their center coordinates range from 0 to
columns-1 horizontally and from 0 to rows-1 vertically. Note that the direction of the vertical axis and thus the default
values for top and bottom depend on *origin*: - For ``origin == 'upper'`` the default is
``(-0.5, numcols-0.5, numrows-0.5, -0.5)``.
- For ``origin == 'lower'`` the default is
``(-0.5, numcols-0.5, -0.5, numrows-0.5)``. See the :doc:`/tutorials/intermediate/imshow_extent` tutorial for
examples and a more detailed description. filternorm : bool, optional, default: True
A parameter for the antigrain image resize filter (see the
antigrain documentation). If *filternorm* is set, the filter
normalizes integer values and corrects the rounding errors. It
doesn't do anything with the source floating point values, it
corrects only integers according to the rule of 1.0 which means
that any sum of pixel weights must be equal to 1.0. So, the
filter function must produce a graph of the proper shape. filterrad : float > 0, optional, default: 4.0
The filter radius for filters that have a radius parameter, i.e.
when interpolation is one of: 'sinc', 'lanczos' or 'blackman'. resample : bool, optional
When *True*, use a full resampling method. When *False*, only
resample when the output image is larger than the input image. url : str, optional
Set the url of the created `.AxesImage`. See `.Artist.set_url`. Returns
-------
image : `~matplotlib.image.AxesImage` Other Parameters
----------------
**kwargs : `~matplotlib.artist.Artist` properties
These parameters are passed on to the constructor of the
`.AxesImage` artist. See also
--------
matshow : Plot a matrix or an array as an image. **X:**
图像数据。支持的数组形状是:
(M,N) :带有标量数据的图像。数据可视化使用色彩图。
(M,N,3) :具有RGB值的图像(float或uint8)。
(M,N,4) :具有RGBA值的图像(float或uint8),即包括透明度。
前两个维度(M,N)定义了行和列图片,即图片的高和宽;
RGB(A)值应该在浮点数[0, ..., 1]的范围内,或者
整数[0, ... ,255]。超出范围的值将被剪切为这些界限。
**cmap:**
将标量数据映射到色彩图
颜色默认为:rc:image.cmap。
**norm :**
~matplotlib.colors.Normalize
如果使用scalar data ,则Normalize会对其进行缩放[0,1]的数据值内。
默认情况下,数据范围使用线性缩放映射到颜色条范围。 RGB(A)数据忽略该参数。
**aspect:**
{'equal','auto'}或float,可选
控制轴的纵横比。该参数可能使图像失真,即像素不是方形的。
equal:确保宽高比为1,像素将为正方形。(除非像素大小明确地在数据中变为非正方形,坐标使用 extent )。
auto: 更改图像宽高比以匹配轴的宽高比。通常,这将导致非方形像素。
**interpolation:**
str
使用的插值方法
支持的值有:'none', 'nearest', 'bilinear', 'bicubic','spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser',
'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc','lanczos'.
如果interpolation = 'none',则不执行插值
**alpha:**
alpha值,介于0(透明)和1(不透明)之间。RGBA输入数据忽略此参数。
**vmin, vmax : scalar,**
如果使用* norm 参数,则忽略 vmin , vmax *。
vmin,vmax与norm结合使用以标准化亮度数据。
**origin : {'upper', 'lower'}**
将数组的[0,0]索引放在轴的左上角或左下角。
'upper'通常用于矩阵和图像。
请注意,垂直轴向上指向“下”但向下指向“上”。
**extent:(left, right, bottom, top)**
数据坐标中左下角和右上角的位置。 如果为“无”,则定位图像使得像素中心落在基于零的(行,列)索引上。
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(123456789)
data = np.random.rand(25).reshape(5, 5) #plt.imshow()绘制一组矩阵或数组图像
#cmap设置配色方案,origin设置数组的索引方向,aspect设置坐标轴纵横比,vmin和vmax设置显示的值范围,
#alpha设置透明度,interpolation设置插值方法(默认为None)
plt.imshow(data,cmap='viridis', origin='lower', aspect='auto',vmin=-0.8, vmax=0.8, alpha=0.7, interpolation='None')
#plt.colorbar()绘制简单颜色条
plt.colorbar()

#xlim,ylim设置x轴和y轴的坐标范围
plt.imshow(data,cmap='viridis', origin='lower', aspect='auto',vmin=-0.8, vmax=0.8, alpha=0.7, interpolation='None')
plt.xlim(-1,5)
plt.ylim(5,-1)
plt.colorbar()

#interpolation用于设置插值方法
inter_list = ['nearest', 'bilinear', 'bicubic','spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser',
'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc','lanczos'] fig = plt.figure()
fig.subplots_adjust(hspace=0.6, wspace=0.2)
for i,itype in zip(range(1,17),inter_list):
ax = fig.add_subplot(4,4,i)
ax.imshow(data, cmap='viridis', origin='lower', interpolation=itype)
ax.set_title(itype)

Matplotlib绘图设置---颜色条设置的更多相关文章

  1. matplotlib设置颜色、标记、线条,让你的图像更加丰富

    今天是数据处理专题的第11篇文章,我们继续来介绍matplotlib这个包的使用方法. 在上一篇文章当中我们介绍了matplotlib当中subplot的概念以及用法,今天我们将会来介绍matplot ...

  2. 为ProgressBar进度条设置颜色1

    可以通过xml文件来设置,方法如下: 1:先在布局文件中的ProgressBar加入下面属性: android:progressDrawable="@drawable/progress_ba ...

  3. Matplotlib绘图双纵坐标轴设置及控制设置时间格式

    双y轴坐标轴图 今天利用matplotlib绘图,想要完成一个双坐标格式的图. fig=plt.figure(figsize=(20,15)) ax1=fig.add_subplot(111) ax1 ...

  4. matplotlib绘图教程,设置标签与图例

    大家好,欢迎大家阅读周四数据处理专题,我们继续介绍matplotlib作图工具. 在上一篇文章当中我们介绍了matplotlib这个包当中颜色.标记和线条这三种画图的设置,今天我们同样也介绍三种新的设 ...

  5. Python matplotlib绘图设置图例

    一.语法简介 plt.legend(loc=2,edgecolor='red',facecolor='green',shadow='True',fontsize=10) #edgecolor 图例边框 ...

  6. Python matplotlib绘图设置坐标轴的标题

    一.语法简介 plt.xlabel("销售月份",fontsize=16,color='red',fontweight='bold',loc='center',background ...

  7. ios中用drawRect方法绘图的时候设置颜色

    设置画笔颜色可以直接 [[UIColor grayColor] set];就可以设置颜色.

  8. python中matplotlib绘图封装类之折线图、条状图、圆饼图

    DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...

  9. 4.13Python数据处理篇之Matplotlib系列(十三)---轴的设置

    目录 目录 前言 (一)设置轴的范围 1.同时对于x,y轴设置 2.分别对与x,y轴的设置 (二)设置刻度的大小 1.普通的刻度设置 2.添加文本的刻度设置 3.主副刻度的设置 (三)设置轴的数据 1 ...

  10. leangoo更换背景、设置颜色标签功能上线啦!

    leangoo看板背景太单调?卡片标签想要添加多个?没有问题,Leangoo的本次更新就给大家带来了漂亮背景和实用的颜色标签设置,接下来就让我们一起来看看吧! 设置背景: 点击看板右上角个人头像图标按 ...

随机推荐

  1. ASP.NET 通过拦截器记录错误日志

    前言 主要是记录一下实现的错误日志拦截,可以在拦截器里面控制返回的信息,把错误信息处理后返回给请求端. 代码实战 拦截器 /// <summary> /// 接口异常捕捉过滤器 /// & ...

  2. 【LeetCode二叉树#06】获取二叉树的所有路径(分析递归中的回溯机制)

    二叉树所有路径 力扣题目链接(opens new window) 给定一个二叉树,返回所有从根节点到叶子节点的路径. 说明: 叶子节点是指没有子节点的节点. 示例: 思路 根据题意,每次遍历至子节点, ...

  3. 【Azure API 管理】APIM Self-Host Gateway 自建本地环境中的网关数量超过10个且它们的出口IP为同一个时出现的429错误

    问题描述 Azure API Management服务支持使用自建网关来实现API服务,这样APIM的所有请求都可以走在自管理的企业内网中.流量都更加安全.当根据官网文档搭建后,如果在本地环境中部署超 ...

  4. 百亿节点、毫秒级延迟,携程金融基于 NebulaGraph 的大规模图应用实践

    作者:霖雾,携程数据开发工程师,关注图数据库等领域. 0. 背景 2017 年 9 月携程金融成立,在金融和风控业务中,有多种场景需要对图关系网络进行分析和实时查询,传统关系型数据库难以保证此类场景下 ...

  5. 9、mysql的并发参数调整

    从实现上来说,MySQL Server 是多线程结构,包括后台线程和客户服务线程.多线程可以有效利用服务器资源,提高数据库的并发性能.在Mysql中,控制并发连接和线程的主要参数包括 max_conn ...

  6. 远程服务调用(RPC与Rest本质区别)

    一.背景 远程服务将计算机程序的工作范围从单机扩展到网络,从本地延伸至远程,是构建分布式系统的首要基础.远程服务调用(Remote Procedure Call,RPC)在计算机科学中已经存在了超过四 ...

  7. 使用PdfSharp从模板生成Pdf文件

    ​ 最近在做一个生成文档的需求.通过先制作一个包含各字段占位符的文档模板,导入这个模板并填写内容替换掉占位符,再输出成最终文件. 由于版式固定,安全性更好,业务上常用Pdf作为最终标准化的格式, 在. ...

  8. Spring事务(五)-事务隔离级别

    Spring @Transactional注解isolation属性 @Transactional注解通过isolation属性设置事务隔离级别.如下: @Transactional(isolatio ...

  9. Linux 使用 selenium 环境配置

    1.需要安装 Chrome 浏览器 yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64 ...

  10. Error: Command failed: C:\windows\system32\cmd.exe /s /c "./configure --disable-shared

    错误记录之: Error: Command failed: C:\windows\system32\cmd.exe /s /c "./configure --disable-shared 错 ...