Problem with overlapping bars in a plot with 2 y axis.
Show older comments
I am trying to plot a bar chart with 2 y-axes in MATLAB. The 2-axes feature works, however, the bars are overlapping. Also, the categories on the right-hand axis should have different colors, not the same red. How can this be done? Also, how can I label both y axes? Here is the code I am using:
C1=[0.9;0.89;0.65;0.05;0.01;0.01]
C2=[7.76 9.42;7.7 9.14;8.4 6.3;8.5 6;9.6 7.1;9.5 7.15]
yyaxis left
bar(C1)
ylim([0 1.1])
yyaxis right
bar(C2);
ylim([0 12])
set(gca,'XTickLabel',{'0.013 g','0.13 g','0.27 g','0.67 g','1.30 g','2.7 g'},'FontWeight','bold')
legend('Nitrate removal','pH','DO','FontWeight','bold')
ylabel('pH/DO','FontWeight','bold')
xlabel('Amount of NPs (g)','FontWeight','bold')
Answers (1)
dpb
on 26 May 2019
0 votes
Answers/325849 bar graph with two yaxes Illustrates how to solve this...it's a pain TMW hasn't built a routine for such already; it's an obvious shortcoming.
Categories
Find more on Bar Plots 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!