Set limit on secondary y axis

조회 수: 28 (최근 30일)
AU
AU 2019년 6월 1일
댓글: AU 2019년 6월 1일
I want to set the limit on my secondary y axis to -320 and 1600. Using the following code, the inititial limits are not changed. It seems like it doesnt even consider the line with the ylim.
% Colors
fig = figure;
left_color = [0, 0.4470, 0.7410];
right_color = [0.6350, 0.0780, 0.1840];
set(fig,'defaultAxesColorOrder',[left_color; right_color]);
% Plot Closing Price and Volume
figure(1)
yyaxis left
b = bar(TimeWindowB,Dependent_v.Volume);
yyaxis right
ylim ([-320 1600]);
p = plot(TimeWindowB,Dependent_v.Close,'LineWidth',1.25);
title('Closing Price and Volume per Trading Day')
legend({'Volume','Close'},'Location','northwest','Orientation','horizontal')

채택된 답변

Sajeer Modavan
Sajeer Modavan 2019년 6월 1일
편집: Sajeer Modavan 2019년 6월 1일
You were applying ylim before ploting, that is why its not working properly. I hope this graph will be accepted.
Capture.JPG
TimeWindowB = 1:10;
Nt = length(TimeWindowB);
Dependent_v.Volume = 5*(1:Nt);
Dependent_v.Close = -320:(320+1600)/(Nt-1):1600;
%=========================================================
fig = figure;
left_color = [0, 0.4470, 0.7410];
right_color = [0.6350, 0.0780, 0.1840];
set(fig,'defaultAxesColorOrder',[left_color; right_color]);
% Plot Closing Price and Volume
yyaxis left
b = bar(TimeWindowB,Dependent_v.Volume);
yyaxis right
p = plot(TimeWindowB,Dependent_v.Close,'LineWidth',1.25);
ylim ([-320 1600]);
title('Closing Price and Volume per Trading Day')
legend({'Volume','Close'},'Location','northwest','Orientation','horizontal')

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by