フィルターのクリア

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 Center および File ExchangeBar Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by