plotyy - how to change line width, colour and xaxis labels
Show older comments
Hi all,
I am trying to use the plotyy function to plot a bar chart with a line graph on top. Generally I have managed to achieve what I was after but would also like to change the line thickness (the hLine.LineWidth = 3; doesn't seem to work), the colour (ditto with hLine.Color = [159/255 20/255 124/255; 70/255 32/255 112/255];) and the xaxis labels are displaying correctly but underneath are the values 1,2,3, etc. This is my code
figure
set(0,'DefaultAxesFontName', 'Aller')
[ax,hBar,hLine]=plotyy(1:13,[aircraft.median_2011;aircraft.median_2013]', ...
1:13,[aircraft.count_2011;aircraft.count_2013]', ...
'bar','semilogy')
legend('2011','2013')
ylabel(ax(1),'Joining Point (nm)')
ylabel(ax(2),'No. of Flights')
str = [aircraft.name];
set(gca, 'XTickLabel',str, 'XTick',1:numel(str));
barmap=[159/255 20/255 124/255; 70/255 32/255 112/255]; %[0.7 0.7 0.7] is grey, [ 0.05 .45 0.1] is green
colormap(barmap);
hLine.LineWidth = 3;
hLine.Color = [159/255 20/255 124/255; 70/255 32/255 112/255];
If anyone knows how to do any of these help would be very much appreciated.
Cheers
2 Comments
Robert Cumming
on 5 Jan 2015
what version of matlab?
any error message(s)?
Also - we dont have your aircraft variable to recreate your plots exactly.
Mike Garrity
on 6 Jan 2015
I think that it should have reported the following error
Incorrect number of right hand side elements in dot name assignment. Missing []
around left hand side is a likely cause.
That's not as helpful as it could be. It's really the left hand side that's the issue here.
Accepted Answer
More Answers (1)
Mike Garrity
on 6 Jan 2015
0 votes
Because each of your two plots contains two series, the variable hLine is an array of two line objects. Unfortunately, dot notation doesn't work on arrays of objects yet. That means that you need to use set like dpb showed above.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!