什么是默认的MATLAB颜色顺序? [英] What is the default MATLAB Color Order?

查看:6458
本文介绍了什么是默认的MATLAB颜色顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个直方图的MATLAB图。然而,很难判断绘图上的哪个直方图来自第一组数据,以及哪个绘制第二组数据。每个直方图有一条不同的彩色线:一个是蓝色的,另一个是绿色的。设备之间的默认MATLAB颜色顺序是否不同?如果没有,顺序是什么?

解决方案

好问题! MATLAB有一个默认的颜色顺序。注意,在R2014b之前的版本,MATLAB的默认颜色顺序使用喷气式彩色地图。在喷墨彩色图中,第一个图是蓝色的,第二个图是绿色的。对于R2014b之后的版本,这遵循parula颜色图,其中第一个图是浅蓝色,第二个图是铜橙色。如果你真的想知道你的情节的颜色顺序,请确保该图在MATLAB中打开,然后执行以下操作:

  get(gca,'colororder')

这将返回一个2D矩阵,你生成的每个图的红色,绿色和蓝色的比例。在我的机器在这篇文章的时候,当我运行MATLAB R2013a和Mac OSX 10.9.5,这是我得到:

 >> get(gca,'colororder')

ans =

0 0 1.0000
0 0.5000 0
1.0000 0 0
0 0.7500 0.7500
0.7500 0 0.7500
0.7500 0.7500 0
0.2500 0.2500 0.2500

每行给出特定颜色的红色,绿色和蓝色值。



因此,上面的颜色顺序是:第一行表示第一个颜色,第二个表示第二个颜色,


  1. 纯蓝色

  2. 较浅的绿色

  3. 纯红色

  4. 绿色和蓝色的混合物,是青色

  5. 红色和蓝色的混合物,是洋红色

  6. 红色和绿色的混合物,是黄色的

  7. 红色,绿色和蓝色的混合色,看起来像是深灰色。

目前(2016年3月10日),我使用MATLAB R2015a,这是我得到的颜色图:

 >> get(gca,'colororder')

ans =

0 0.4470 0.7410
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
0.4660 0.6740 0.1880
0.3010 0.7450 0.9330
0.6350 0.0780 0.1840






p>作为额外的奖励,我们可以创建一个可视化这些颜色为您的图像。假设你有图像处理工具箱,这是我写的代码,以可视化你放置在你的图中的每个情节的颜色。

  colors = permute(get(gca,'colororder'),[1 3 2]); 
colours_resize = imresize(colors,50.0,'nearest');
imshow(colours_resize);

这是我为MATLAB R2013a:





在MATLAB R2015a中再次运行此代码,这是我得到的:








始终使用 图例 ,描述什么直方图来自哪些数据。


There is a MATLAB plot with two histograms. However, it is difficult to tell which histogram on the plot is coming from the first set of data and which graphs the second set of data. There is a different colored line for each histogram: One is blue, and the other is green. Does the default MATLAB Color Order vary between devices? If not, what is the order?

解决方案

Good question! There is a default colour order for MATLAB. Take note that versions before R2014b, the default colour order for MATLAB uses the jet colour map. In the jet colour map, the first plot is blue, followed by the second plot being green. For versions after R2014b, this follows the parula colour map, where the first plot would be a lighter blue followed by the second plot being a copper orange of sorts. If you actually want to know what the colour order is for your plot, make sure the plot is open in MATLAB, then do the following:

get(gca,'colororder')

This will return a 2D matrix where each row gives you the proportion of red, green and blue for each plot that you produce. On my machine at the time of this post when I was running MATLAB R2013a and with Mac OSX 10.9.5, this is what I got:

>> get(gca,'colororder')

ans =

         0         0    1.0000
         0    0.5000         0
    1.0000         0         0
         0    0.7500    0.7500
    0.7500         0    0.7500
    0.7500    0.7500         0
    0.2500    0.2500    0.2500

Each row gives you the red, green and blue values for a particular colour. The first row denotes the first colour to go on the plot, followed by the second row denoting the second colour and so on.

As such, the above colour order is:

  1. Pure blue
  2. A lighter shade of green
  3. Pure red
  4. A mixture of green and blue, which is cyan
  5. A mixture of red and blue, which is magenta
  6. A mixture of red and green which is yellow
  7. A light mixture of red, green and blue, which looks like a dark gray.

Currently (March 10th, 2016), I am using MATLAB R2015a and this is the colour map I get:

>> get(gca,'colororder')

ans =

         0    0.4470    0.7410
    0.8500    0.3250    0.0980
    0.9290    0.6940    0.1250
    0.4940    0.1840    0.5560
    0.4660    0.6740    0.1880
    0.3010    0.7450    0.9330
    0.6350    0.0780    0.1840

The RGB tuples in this case are slightly more complex and so it's hard to infer what they are by just looking at the colours.


As an additional bonus, we can create an image that visualizes these colours for you. Assuming you have the image processing toolbox, this is the code I wrote to visualize those colours for each plot you place in your figure.

colours = permute(get(gca, 'colororder'), [1 3 2]);
colours_resize = imresize(colours, 50.0, 'nearest');
imshow(colours_resize);

Here's what I got for MATLAB R2013a:

Running this code again in MATLAB R2015a, this is what I get:


Alternatively, you can always use a legend that delineates what histogram comes from which data.

这篇关于什么是默认的MATLAB颜色顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆