![190628 145939-Figure 2.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226813/190628%20145939-Figure%202.jpeg)
How to specify limit of right y axis, and add values above bar
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Adam Danz
2019년 6월 28일
편집: Adam Danz
2019년 6월 28일
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226813/190628%20145939-Figure%202.jpeg)
댓글 수: 6
참고 항목
카테고리
Help Center 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!