Set limit on secondary y axis

33 vues (au cours des 30 derniers jours)
AU
AU le 1 Juin 2019
Commenté : AU le 1 Juin 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')

Réponse acceptée

Sajeer Modavan
Sajeer Modavan le 1 Juin 2019
Modifié(e) : Sajeer Modavan le 1 Juin 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')
  1 commentaire
AU
AU le 1 Juin 2019
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by