Change scale of second y-axis on figure

1 次查看(过去 30 天)
Hello,
I have a figure with two axis, one of which is inverted. The inverted axis needs to be compressed in the y direction so the bars do not ovelap.
Here's my current code, and the figure result is attached.
%% Plot of summary table vs month/day AVERAGES for study period (Jul 2019 to Sep 2020) SUMMER
fig1 = figure; % Summer Precip
hAxes(1) = subplot(2, 1, 1);
yyaxis left
bar(1:height(P2SFL_P_DSsummerperiod_summarytable),P2SFL_P_DSsummerperiod_summarytable.mean_Var1, 'FaceColor', 'blue')
axis ij
ylabel('[mm]')
ylim([0 10])
hold on
yyaxis right
bar(1:height(P2SFL_KE_DSsummerperiod_summarytable),P2SFL_KE_DSsummerperiod_summarytable.mean_Var1)%, 'FaceColor', 'black')
% Decide how many ticks you want. This does every 10 rows (10 days if none missing)
tick_idx = 1:7:height(P2SFL_KE_DSsummerperiod_summarytable);
xticks(tick_idx)
% Label ticks with month and day (e.g., "July 1")
xticklabels(string(P2SFL_KE_DSsummerperiod_summarytable.Month(tick_idx))+" "+P2SFL_KE_DSsummerperiod_summarytable.Day(tick_idx))
% Angle ticks at 45 degrees for easier reading when closely packed
xtickangle(45)
title('CBBG-SFL, Mesa, AZ')%, 'FontSize', 15)
ylabel('[J/m^2]')
%ylim([0 15])
%xlabel('Month and Day')
hAxes(2) = subplot(2, 1, 2);
yyaxis left
bar(1:height(P2JER_P_DSsummerperiod_summarytable),P2JER_P_DSsummerperiod_summarytable.mean_Var1, 'FaceColor', 'blue')
axis ij
ylabel('[mm]')
hold on
yyaxis right
bar(1:height(P2JER_KE_DSsummerperiod_summarytable),P2JER_KE_DSsummerperiod_summarytable.mean_Var1) %, 'FaceColor', 'black')
% Decide how many ticks you want. This does every 10 rows (10 days if none missing)
tick_idx = 1:7:height(P2JER_KE_DSsummerperiod_summarytable);
xticks(tick_idx)
% Label ticks with month and day (e.g., "July 1")
xticklabels(string(P2SFL_KE_DSsummerperiod_summarytable.Month(tick_idx))+" "+P2SFL_KE_DSsummerperiod_summarytable.Day(tick_idx))
% Angle ticks at 45 degrees for easier reading when closely packed
xtickangle(45)
%set(gca,'xticklabel',{[]})
title('JER, Las Cruces, NM')%, 'FontSize', 15)
ylabel('[J/m^2]')
%ylim([20 30])
% Give common xlabel, ylabel and title to your figure
linkaxes(hAxes, 'x');
%xlim([1 92])
han=axes(fig1,'visible','off');
han.Title.Visible='on';
han.XLabel.Visible='on';
han.YLabel.Visible='off';
%xlabel(han,'Month and Day');
%title(han,'Las Cruces International Airport, Summer Season (2001-2020)');
sgtitle('Daily Average Precipitation and Kinetic Energy, Summer Season (2019-2020)')
Thanks!

回答(1 个)

Cris LaPierre
Cris LaPierre 2020-9-30
Use the ylim function to set the yaxis limits.

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by