필터 지우기
필터 지우기

How to specify limit of right y axis, and add values above bar

조회 수: 2 (최근 30일)
Ali Tawfik
Ali Tawfik 2019년 6월 28일
편집: Adam Danz 2019년 7월 15일
Hi All,
I am kindly asking for help to specify limits in the right y-axis (I have been trying to use a lot of commands but not working , mine is 2016a ) as well as I'd like to intrdouce the values above bars.
figure1=figure;
E = [31 15.5 72.2 36 71.6 700 590 610;zeros(1,8)]'
sigma = [zeros(1,8);940 2020 3550 99.8 2413 54000 21000 27000]'
[hAx,H1,H2] =plotyy([1:8],sigma, [1:8],E, 'bar', 'bar');
set(H1,'FaceColor','r') %
set(H2,'FaceColor','b') %
x_axisname={'x','y','z','notshown','xx','yy','zz','K'};
set(gca,'xticklabel',x_axisname)
mul_axes=legend([H1(1) H2(1)],'E','strength','FontSize',31); % name for multiple axes
lgd.FontSize = 31;
%ylim([0 10])
set(hAx,'FontSize',31)
set(gca,'FontSize',31);
hold off

답변 (1개)

Adam Danz
Adam Danz 2019년 6월 28일
편집: Adam Danz 2019년 6월 28일
Starting 2016a, you should use yyaxis() instead of plotyy().
figure1=figure;
E = [31 15.5 72.2 36 71.6 700 590 610;zeros(1,8)]';
sigma = [zeros(1,8);940 2020 3550 99.8 2413 54000 21000 27000]';
yyaxis left
H1 = bar(1:size(sigma,1), sigma, 'FaceColor', 'r');
text(H1(2).XData,H1(2).YData, strsplit(num2str(H1(2).YData)),'VerticalAlignment','bottom','HorizontalAlignment','Left')
set(gca,'YColor', 'r')
ylabel('Sigma')
yyaxis right
H2 = bar(1:size(E,1), E, 'FaceColor', 'b');
ylim([0,800])
text(H2(1).XData,H2(1).YData, strsplit(num2str(H2(1).YData)),'VerticalAlignment','bottom','HorizontalAlignment','Right')
set(gca,'YColor', 'b')
ylabel('E')
x_axisname={'x','y','z','notshown','xx','yy','zz','K'};
set(gca,'xticklabel',x_axisname)
mul_axes=legend([H1(1) H2(1)],'strength','E','FontSize',31); % name for multiple axes
lgd.FontSize = 31;
set(gca,'FontSize',31);
hold off
190628 145939-Figure 2.jpg
  댓글 수: 6
Ali Tawfik
Ali Tawfik 2019년 7월 3일
Hi Adam,
you are right, I have checked and found the mistake.
Again, thanks for your kind, I also added another question, hope you could have a look, and let me know your opinion :)
thanks,
Adam Danz
Adam Danz 2019년 7월 8일
편집: Adam Danz 2019년 7월 15일
Glad I could help.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by