Matlab中的条形图开关颜色 [英] Bar plot switch colors in Matlab

查看:124
本文介绍了Matlab中的条形图开关颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Matlab中有以下代码,它对我有用.现在,我想使该图与另一图在颜色上可比.因此,应切换一些颜色:...的颜色

I have the following code in Matlab, which produces a useful plot for me. Now I'd like to make the plot comparable color wise with another plot. For this reason, some colors should be switched: colors for...

拆分前总EON"和拆分后总EON"

'Pre split total EON' with 'Post split total EON'

"Pre split pure EON"和"Post split pure EON"

'Pre split pure EON' with 'Post split pure EON'

"Pre split total RWE"和"Post split total RWE"

'Pre split total RWE' with 'Post split total RWE'

"Pre split pure RWE"和"Post split pure RWE".

'Pre split pure RWE' with 'Post split pure RWE'.

仅此而已,但我不知道该怎么做,因为颜色是自动分配的...

That is all, but I do not know how to do it, since the colors are assigned automatically...

clear all
close all

values = [4 1 11 2 3; 4 1 5 2 -10];
names = {'Pre split total EON' 'Post split total EON'...
    'Pre split pure EON' 'Post split pure EON' 'Post split Uniper';...
    'Pre split total RWE' 'Post split total RWE'...
    'Pre split pure RWE' 'Post split pure RWE' 'PostSplitInnogy'};
categories = {'EON','RWE'};
figure;
b = bar(values,'FaceColor','flat');
ticksList = b(1).XData+arrayfun(@(x)x.XOffset, b)';
xticks(ticksList(:))
xticklabels([names(1,:)';names(2,:)'])
xtickangle(90)
ax1 = gca;
ax2 = axes('Position', get(ax1, 'Position'),'Color', 'none');
set(ax2, 'XAxisLocation', 'top','YAxisLocation','Right');
set(ax2, 'XLim', get(ax1, 'XLim'),'YLim', get(ax1, 'YLim'));
set(ax2, 'YTick', []);
xticks(b(1).XData)
xticklabels(categories)
for k = 1:size(values,2) % for fancier colors.
    b(k).CData = k;
end

推荐答案

我觉得您在以下位置手动分配了颜色:

I feel like you assigned the colors manually in:

for k = 1:size(values,2) % for fancier colors.
    b(k).CData = k;
end

如果您只想更改顺序,可以通过

if you just want to change the order you can do so by

b(1).Cdata = 2;

,依此类推.或者,您可以使用

and so on. Alternativly you can change all in one with

[b.CData] = deal(2,1,4,3,5);

这篇关于Matlab中的条形图开关颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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