plotyy line width and color - with multiple lines
61 views (last 30 days)
Show older comments
Hi Everyone, I know there are posts on similar lines but I am having difficulty specifically with plotyy in which I have multiple lines plotted on the left hand axis, with one plotted on the right hand axis. I thought I knew how to set axis properties but when I set the line width it sets the width of the box around the axis! Also I am trying to define the colours of each of the lines but it is just making the whole background of the plot blue. I think there must be another layer of handles I'm missing? I've only tried this in the first plot of a subplot.
% %define colours
% colorspec=[0 0 1];[0 1 1];[1 0 0];[1 0 1];[0 0.6 0.4];[1 0.4 0];[0.6 0 0.8];[0 1 0.4];[0 0 0.4];[0.8 0 0.2];[1 0.6 0.2];[0 0.6 1];[0 0.2 0];[0.4 0 0.6];[1 0.6 1];[0.8 1 0.4];[0.8 0.6 0.2];[1 0.8 0];[0.6 0 0.2];[0.6 0.6 0.8];[0.2 0.2 0.4];
%
%
% %Both 2010 and 2011 July velocities
% subplot(2,2,1)
% %horizontal velocities sigma 2010 July
%
% [haxes,hline1,hline2]=plotyy(hvel_July_2010_sigma(2:8,1),hvel_July_2010_sigma(2:8,3:22),hvel_July_2010_sigma(2:8,1),hvel_July_2010_sigma(2:8,27));
% axes(haxes(1))
% ylabel('Horizontal velocity (\sigma)');
% 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),'LineWidth',2);
% set(haxes(1),'Color',colorspec);
% %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'});
Any help with this much appreciated! I am working in Matlab 2010b. The data is attached.
Kind Regards, Cat
0 Comments
Accepted Answer
Mike Garrity
on 28 Jul 2015
The call to plotyy returned 3 things:
[haxes,hline1,hline2] = plotyy( ...
The first (haxes) is an array of two axes handles. Setting properties on these change the axes. For example, these two calls:
set(haxes(1),'LineWidth',2);
set(haxes(1),'Color',colorspec);
set the box of the left axes to be linewidth=2 and the background of the left axes to be blue.
The other two things (hline1 & hline2) are the lines in the axes. Setting properties on these will change the lines. For example, if I change those two lines to this:
set(hline1,'LineWidth',2);
set(hline1,'Color',colorspec);
Then the line in the left axes will be linewidth=2 and blue.
Does that make sense?
A few other things though.
You've got code which sets the XLim and XTick values of your axes to be in the range of [212 218]. However, your XData is the range [-2 2]. Also, your XData values are not monotone. It is possible to use plotyy with nonmonotonic X values, but it's fairly unusual. Could you describe the plot you're trying to get here?
2 Comments
dpb
on 28 Jul 2015
Edited: dpb
on 28 Jul 2015
BTW, it's convenient with plotyy to
linkaxes('x')
so that changes in one are reflected in the other; otherwise you end up with possibly different scales and other funky visual artifacts. I almost always set(hAx(2),'xtick',[]) so only one set of ticks and tick labels will be visible; rendering otherwise every once in a while causes "jitter" that is unpleasing...
Oh, and another tip...use set on any HG object handle to see a list of all its properties and their default values or get to see current values of all...when you know something's got to be there but can't spell or remember the property name or just are looking for how to to something, it's an invaluable aid.
More Answers (1)
dpb
on 28 Jul 2015
The line properties are associated with the line handles, not those of the parent object. In plotyy, they are returned in the two second optional return variables, that you returned has hline1, hline2 for the left- and right-hand axes, respectively. Set the properties for those as desired.
0 Comments
See Also
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!