[英]multiple colours on matlab histogram
Hi I am trying to get multiple colours on a matlab histogram - i think the following should do it: 嗨,我正在尝试在Matlab直方图上获得多种颜色-我认为以下应该做到:
figure
hist(ligand,50)
h=findobj(gca,'Type','patch');
set(h,'FaceColor',[0 .5 .5],'EdgeColor','w')
hold on;
hist(potassium,50)
g=findobj(gca,'Type','patch');
set(g,'FaceColor',[0 1 1],'EdgeColor','w')
hold on;
hist(rectifier,50)
title('Alignment to AFP1')
xlabel('Score'); ylabel('Number of Sequences')
hold off;
where the first colour is [0 .5 .5], the second [0 1 1] and the third is the default colour. 其中第一种颜色是[0 .5 .5],第二种颜色[0 1 1],第三种是默认颜色。 However even though I have specified two separate colours for the first two using two handles, h and g - both are the same colour, using the g handle.
但是,即使我使用两个手柄h和g为前两个指定了两种单独的颜色,也使用g手柄都具有相同的颜色。
What am I doing wrong? 我究竟做错了什么?
edit - this is for Luis Mendos's suggestion - I am getting an "index exceeds matrix dimensions" with the following 编辑-这是路易斯·门多斯(Luis Mendos)的建议-我得到的是“索引超出矩阵尺寸”,内容如下
figure
hist(ligand,50)
g=findobj(gca,'Type','patch');
set(g(1),'FaceColor',[0 .5 .5],'EdgeColor','w')
hold on;
hist(potassium,50)
set(g(2),'FaceColor',[0 1 1],'EdgeColor','w')
hist(rectifier,50)
title('Alignment to AFP1')
xlabel('Score'); ylabel('Number of Sequences')
hold off;
Thanks. 谢谢。
The problem is that g
is a two-element vector, because it includes the two histograms that have already been plotted. 问题在于
g
是一个二元素向量,因为它包括已经绘制的两个直方图。 Remove the lines with h
(lines 3 and 4) and replace the line set(g,...)
by 删除带有
h
的行(第3和4行),并将行set(g,...)
替换为
set(g(1),'FaceColor',[0 .5 .5],'EdgeColor','w')
set(g(2),'FaceColor',[0 1 1],'EdgeColor','w')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.