using a color map in a subplot

9 views (last 30 days)
Catriona
Catriona on 14 Jul 2016
Commented: Bjorn Gustavsson on 15 Jul 2016
Dear Matlab folk, I am trying to graph data from up to 20 different points in 4 subplots, all of which use plotyy. By default Matlab cycles through its 8 colours but really each point should have a different colour (preferably from a nice colour map), and these colours should be consistent across graphs. I have tried a number of things but the best I have been able to do is to turn all of the lines blue. Most examples are not using subplots and plotyy which makes it trickier to get the code right (for me anyway!)I have attached the code for the graph so you can see what I mean (I have commented out a few things I have tried already but not been able to get to work).
Any help you can provide would be much appreciated, Kind Regards, Cat
if true
% code %Both 2010 and 2011 July velocities
figure (2)
a = subplot(2,2,1);
%horizontal velocities sigma 2010 July
[haxes,hline1,hline2]=plotyy(hvel_July_2010_cmd(2:8,1),hvel_July_2010_cmd(2:8,3:22),hvel_July_2010_cmd(2:8,1),hvel_July_2010_cmd(2:8,27));
axes(haxes(1))
ylabel('Horizontal velocity (cm d^-^1)');
xlim([212 218]);
ylim([2 18]);
set(haxes(1),'XTick',[212:218]);
set(haxes(1),'XTickLabel',{'31/07/10','01/08/10','02/08/10','03/08/10','04/08/10','05/08/10','06/08/10'});
%set(hline1,'LineWidth',2);
% clrs = jet(numel(a)); % just a Nx3 array of RGB values
% for ii=1:jet(a)
% set(a(ii),'color',clrs(ii,:));
% end
% for ii=1:21;
% set(hline1,'Color',(Colorset(:,ii)));%This works but just sets all
% lines to last color
% end
set(haxes(1),'colororder',Colorset, 'nextplot', 'replacechildren');
%set(hline1,'Color',(Colorset(:,1)));
%set(hline1,'Color','jet');
%set(haxes(1),'ColorOrder',colorspec(:,2:20),'NextPlot','replacechildren');
%set(hline1,'Color',colorspec);
set(haxes(1),'YTick',[2 6 10 14 18]);
axes(haxes(2))
ylabel('Discharge (m^3 s^-^1)');
xlim([212 218]);
ylim([0 16]);
set(haxes(2),'XTick',[212:218]);
set(haxes(2),'XTickLabel',{'31/07/10','01/08/10','02/08/10','03/08/10','04/08/10','05/08/10','06/08/10'});
%set(hline2,'LineWidth',2);
%set(hline2,'Color',colorspec(:,1));
set(haxes(2),'YTick',[0 4 8 12 16]);
set(haxes(2),'YTickLabel',{0 4 8 12 16});
legend('Discharge','NL1','SL1','C1','E1','C2','C3','C4','C5','C6','C7','C8','E2','C9','C10','E3','C11','W1','C12','E4','C13','Location','EastOutside');
%vertical velocities cmdss 2010 July
subplot(2,2,3)
[haxes,hline1,hline2]=plotyy(vvel_July_2010_cmdss(:,1),vvel_July_2010_cmdss(:,3:22),vvel_July_2010_cmdss(:,1),vvel_July_2010_cmdss(:,27));
axes(haxes(1))
ylabel('Vertical velocity (cm d^-^1)');
xlim([212 218]);
set(haxes(1),'XTick',[212:218]);
set(haxes(1),'XTickLabel',{'31/07/10','01/08/10','02/08/10','03/08/10','04/08/10','05/08/10','06/08/10'});
%set(haxes(1),'YTick',[-2 -1 0 1 2]);
axes(haxes(2))
ylabel('Discharge (m^3 s^-^1)');
xlim([212 218]);
set(haxes(2),'XTick',[212:218]);
set(haxes(2),'XTickLabel',{'31/07/10','01/08/10','02/08/10','03/08/10','04/08/10','05/08/10','06/08/10'});
legend('Discharge','NL1','SL1','C1','E1','C2','C3','C4','C5','C6','C7','C8','E2','C9','C10','E3','C11','W1','C12','E4','C13','Location','EastOutside');
%horizontal velocities sigma 2011 July
subplot(2,2,2)
[haxes,hline1,hline2]=plotyy(hvel_2011_July_cmd(:,1),hvel_2011_July_cmd(:,2:9),hvel_2011_July_cmd(:,1),hvel_2011_July_cmd(:,14));
axes(haxes(1))
ylabel('Horizontal velocity (cm d^-^1)');
xlim([210 214]);
ylim([5 15]);
set(haxes(1),'XTick',[210:214]);
set(haxes(1),'XTickLabel',{'29/07/11','30/07/11','31/07/11','01/08/11','02/08/11'});
set(haxes(1),'YTick',[5 7.5 10 12.5 15]);
axes(haxes(2))
ylabel('Discharge (m^3 s^-^1)');
xlim([210 214]);
set(haxes(2),'XTick',[210:214]);
set(haxes(2),'XTickLabel',{'29/07/11','30/07/11','31/07/11','01/08/11','02/08/11'});
set(haxes(2),'YTick',[0 2.5 5 7.5 10]);
set(haxes(2),'YTickLabel',{'0', '2.5', '5', '7.5', '10'});
legend('Discharge','C4','C5','C6','C7','C8','C9','C10','C11','Location','EastOutside');
%vertical velocities cm day July 2011
subplot(2,2,4)
[haxes,hline1,hline2]=plotyy(vvel_2011_July_cmdss(:,1),vvel_2011_July_cmdss(:,2:11),hvel_2011_July_sigma(:,1),hvel_2011_July_sigma(:,14));
axes(haxes(1))
ylabel('Vertical velocity (cm d^-^1)');
xlim([210 214]);
set(haxes(1),'XTick',[210:214]);
set(haxes(1),'XTickLabel',{'29/07/11','30/07/11','31/07/11','01/08/11','02/08/11'});
%set(haxes(1),'YTick',[-2 -1 0 1 2]);
axes(haxes(2))
ylabel('Discharge (m^3 s^-^1)');
xlim([210 214]);
set(haxes(2),'XTick',[210:214]);
set(haxes(2),'XTickLabel',{'29/07/11','30/07/11','31/07/11','01/08/11','02/08/11'});
%set(haxes(2),'YTick',[2:1:6]);
%set(haxes(2),'YTickLabel',{'06/06/10','08/06/10','10/06/10','12/06/10','14/06/10','16/06/10','18/06/10'});
legend('Discharge','C4','C5','C6','C7','C8','C9','C10','C11','C12','C13','Location','EastOutside');
end

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 14 Jul 2016
To me it sounds like you should use cmlines - a function that you can find in this file exchange submission:
HTH
  2 Comments
Catriona
Catriona on 14 Jul 2016
Thanks Bjorn - cmlines was indeed very helpful, at least I have control of the colormap now. Trying to get distinguishable colors is another matter though. I know there is a function for that but it needs the Image Processing Toolbox which I don't have. I'm trying a few other options though so hopefully will get it sorted soon! Thanks for your help!
Bjorn Gustavsson
Bjorn Gustavsson on 15 Jul 2016
Colour design is (as far as I understand) quite an art to itself, and there I can't guide anyone. While searching the fex for distinguishable a couple of potentially useful submissions popped up. Then it seems there is a number of documents on the web discussing this in all sort of directions...

Sign in to comment.

Categories

Find more on Two y-axis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!