Set limit on secondary y axis

30 visualizzazioni (ultimi 30 giorni)
AU
AU il 1 Giu 2019
Commentato: AU il 1 Giu 2019
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')

Risposta accettata

Sajeer Modavan
Sajeer Modavan il 1 Giu 2019
Modificato: Sajeer Modavan il 1 Giu 2019
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')

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by