Set limit on secondary y axis

30 Ansichten (letzte 30 Tage)
AU
AU am 1 Jun. 2019
Kommentiert: AU am 1 Jun. 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')

Akzeptierte Antwort

Sajeer Modavan
Sajeer Modavan am 1 Jun. 2019
Bearbeitet: Sajeer Modavan am 1 Jun. 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')

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by