Set limit on secondary y axis

26 次查看(过去 30 天)
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 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by