How to add a second Y axis to a bar chart?
1 次查看(过去 30 天)
显示 更早的评论
Hi all , I am trying to make a bar chart with readings of particulate matter. Since one of my observations is an outlier my graph does not look right. Is there anyway I could add a second Y axis to my code?
Thanks in advance for your help
%% pdr bar chart
x1=[ 1 2 3 4 5 6 7 8 9 ];
b1=[12.74 33.47; 71.06 29.25; 43.69 17.20;166.75 111.0; 796.17 3266; 519.0 55.27; 7.18 0; 123.25 0; 25.00 0];%% PM 2.5 readings
y1=bar(x1,b1);
xtips1 = y1(1).XEndPoints;
ytips1 = y1(1).YEndPoints;
labels1 = string(y1(1).YData);
text(xtips1,ytips1,labels1,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
xtips2= y1(2).XEndPoints;
ytips2 = y1(2).YEndPoints;
labels2 = string(y1(2).YData);
text(xtips2,ytips2,labels2,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/346119/image.jpeg)
0 个评论
回答(1 个)
Sara Boznik
2020-8-14
Hi!
I recomend you that you use plotyy.
Below you have an example.
[ax,h1,h2] = plotyy(f,[a',b',d',U'],f,I);
set(ax(1),'YLim',[-2 2])
set(ax(2),'YLim',[-15 15])
set(get(ax(1),'Ylabel'),'String','y_1')
set(get(ax(2),'Ylabel'),'String','y_2')
I hope that this will help you somehow. Good luck.
2 个评论
Sara Boznik
2020-8-14
Sorry, I don't know, I am not so experienced here and I am trying to help as much as I can. And ofc it is very useful to learn something new with this MATLAB Answers.
Wish you best of luck.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!