필터 지우기
필터 지우기

How to add a second Y axis to a bar chart?

조회 수: 2 (최근 30일)
desert_scientist90
desert_scientist90 2020년 8월 14일
댓글: Sara Boznik 2020년 8월 14일
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')

답변 (1개)

Sara Boznik
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
desert_scientist90
desert_scientist90 2020년 8월 14일
Thanks I tried plotty but this version of matlab does not recommend using it and give me a code error. I think, I might have to log transform the values
Sara Boznik
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by