在Matlab中的彩条 - 轴刻度 [英] Colorbar - axis ticks in Matlab

查看:746
本文介绍了在Matlab中的彩条 - 轴刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码

d3 = vals;
n = datesmonth;
figure
plot(n,d3);
colormap(jet(12));
hold on
plot(n, d3,'b-');
scatter(n, d3, [], RiskierInd, 'filled');
caxis([1 12]);
colorbar('YTick',[1:12],...
         'YTickLabels',{'Non-Durables','Durables','Manufacturing','Oil, Gas and Coal ','Chemicals','Technology','Telephone & TV','Utilities','Wholesale and Retail','Health','Finance','Other'})
datetick('x','mm-yyyy')

以产生此图

我有两个快速问题:


  1. 是否可以将每个颜色的颜色条字符串条目居中?例如,条目Non-Durables不应该在颜色条的底部,而是在最深的蓝色类别的中间。

  1. Is it possible to center the color bar string entries for each color? For example, the entry "Non-Durables" should not be at the bottom of color bar, but in the middle of the darkest blue category.

可以手动选择每个类别的颜色?

Is it possible to manually choose the colors for each category?


推荐答案

回答了第一个问题。但是,为了完整性,只需这样做,并替换您当前的 caxis 调用:

Ratbert pretty much answered the first question. However, for the sake of completeness, simply do this and replace your current caxis call:

caxis([0.5 12.5]);

要回答第二个问题,是的,可以。

To answer the second question, yes you can.

如果您在代码中注意到,您已从 jet 主题中生成了12个组件的颜色图。这会产生一个12 x 3的矩阵,其中每个是唯一的颜色。因此,如果你想手动选择颜色,你只需要重新排列颜色进来的顺序。如果你看着地图中的颜色条标签,第一种颜色从底部或蓝色开始,

If you notice in your code, you produced a colour map of 12 components from the jet theme. This produces a 12 x 3 matrix where each row is a unique colour. As such, if you want to manually choose the colours, you simply have to rearrange what order the colours come in. If you look at the colour bar label in your plot, the first colour starts from the bottom, or blue, and it progresses to the top, or red.

作为参考,这是由 jet(12)产生的矩阵

>> cmap = jet(12)

cmap = 

     0         0    0.6667
     0         0    1.0000
     0    0.3333    1.0000
     0    0.6667    1.0000
     0    1.0000    1.0000
0.3333    1.0000    0.6667
0.6667    1.0000    0.3333
1.0000    1.0000         0
1.0000    0.6667         0
1.0000    0.3333         0
1.0000         0         0
0.6667         0         0

每一行包含一个唯一的RGB元组,其中第一列表示红色,第二是绿色量,第三是蓝色量。因此,第一对颜色纯粹是蓝色的,然后绿色的渐变增量在这一点之后增加以使其变成青色等等。

Each row contains a unique RGB tuple, where the first column denotes the amount of red, second the amount of green and third the amount of blue. Therefore, the first couple of colours are purely blue, and then shades of green are incrementally added after that point to make it cyan and so on and so forth.

矩阵被布置为使得第一颜色是第一行,最后一个颜色是最后一行。如果您想决定要为哪个标签使用哪种颜色,只需要重新排列行即可匹配您想要的标签。

The matrix is arranged such that the first colour is the first row and the last colour is the last row. If you want to decide which colours you want for which label, you simply need to re-arrange the rows so that it matches whichever label you want.

因此,您有一组标签:

labels = {'Non-Durables','Durables','Manufacturing','Oil, Gas and Coal ','Chemicals','Technology','Telephone & TV','Utilities','Wholesale and Retail','Health','Finance','Other'};

...目前,您有一个颜色出现在颜色图中的顺序:

... and currently, you have an order of which colour appears in the colour map:

cmap = jet(12);
order = [1 2 3 4 5 6 7 8 9 10 11 12]; %// or order = 1:12;
cmap = cmap(order,:);

所有你需要做的就是更改 order 使您获得正确的颜色以正确的顺序显示。因此,请查看图像中的颜色条,并将每种颜色的位置排列为符合 order 的相同位置。例如,如果您想颠倒颜色排序,请执行以下操作:

All you have to do is change order so that you get the right colour to appear in the right order. Therefore, consult the colour bar in your image, and make the positions of each colour be arranged so that it conforms to the same positions of order. For example, if you wanted to reverse the colour ordering, you would do this:

cmap = jet(12);
order = [12 11 10 9 8 7 6 5 4 3 2 1]; %// or order = 12:-1:1;
cmap = cmap(order,:);

同样,如果你想要黄色和青色的颜色先来,将执行:

Similarly, if you wanted the yellow and cyan colours to come first and the rest to come after, you would do:

cmap = jet(12);
order = [8 4 5 6 7 1 2 3 9 10 11 12];
cmap = cmap(order,:); 

一旦你这样做,你调用 colormap cmap 上继续您的情节:

Once you do this, you call colormap on cmap and continue with your plot:

%// From before
cmap = jet(12);
order = [4 5 6 8 7 1 2 3 9 10 11 12];
cmap = cmap(order,:); 

%// New
colormap(cmap);
hold on
plot(n, d3,'b-');
scatter(n, d3, [], RiskierInd, 'filled');
caxis([0.5 12.5]); %// Change
colorbar('YTick',[1:12],...
         'YTickLabels',{'Non-Durables','Durables','Manufacturing','Oil, Gas and Coal ','Chemicals','Technology','Telephone & TV','Utilities','Wholesale and Retail','Health','Finance','Other'})
datetick('x','mm-yyyy')






如果你想手动选择颜色,那将是一个更多的参与。你只需要知道你想要什么颜色,然后将它们放入矩阵。记住,每种颜色是一个RGB元组,并放在一行。


However, if you want to manually choose the colours yourself, that'll be a bit more involved. You'd just need to know what colours you'd want then place them into the matrix. Remember, each colour is a RGB tuple and is placed in a single row. You'd have to look at a colour picker though to know what each component should be weighted as to get the right colour.

前往这里: http://colorpicker.com - 您可以选择所需的确切颜色,并记录RGB值。之后,将每个值除以255,并将其作为颜色映射矩阵中的条目。每种颜色是一行,其中第一列是红色,第二列绿色和第三列蓝色。这是如果你真的想要控制什么颜色与什么类别。

Go here: http://colorpicker.com - You can choose the exact colour you want and record the RGB values. After, divide each value by 255 and place this as an entry in your colour map matrix. Each colour is a row where the first column is the red, second column green and third column blue. This is if you truly want to control what colour goes with what category. You'll have to get right down to determining the right combination of red, green and blue values.

祝你好运!

这篇关于在Matlab中的彩条 - 轴刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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