Incorrect values using ytickformat
Show older comments
Dear all,
I would like to reduce the number of dcp for my right y axis. However, when using ytickformat, instead of reducing the number of dcp, I get a totally different set of y values. Below I have included two images to illustrate my problem.
A) I would like to change 4.54752 to just 4.54.

B) But when I apply attempt to do so I get this.

My code is included below.
x_decade = 1:10;
figure(2);
% Go to left y axis
yyaxis left;
p1 = plot(x_decade,sum_ET10(1,:),'-k',x_decade,sum_P10(1,:),'-b', x_decade,sum_Runoff10(1,:),'-r', x_decade,sum_dSdt10(1,:),'-c', x_decade,sum_C10(1,:),'-g');
p1(1).LineWidth = 2;
p1(2).LineWidth = 2;
p1(3).LineWidth = 2;
p1(4).LineWidth = 2;
p1(5).LineWidth = 2;
yt = get(gca,'YTick');
ylabel('km^3/year')
% Go to right y axis
yyaxis right;
% Evenly space the right y limits according to left y axis
ytr = linspace(min(ylim), max(ylim), numel(yt));
% Convert the right y axis into mm/month
y1 = yt/2199000*1000000;
set(gca, 'YTick',ytr, 'YTickLabel',y1);
ytickformat('%.2f');
ylabel('mm/year');
% Rename x axis variables
set(gca, 'xtick', [1;2;3;4;5;6;7;8;9;10]);
set(gca,'xticklabels',['00-09';'10-19';'20-29';'30-39';'40-49';'50-59';'60-69';'70-79';'80-89';'90-99']);
Any help is greatly appreciated. Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on Axes Appearance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!