Effacer les filtres
Effacer les filtres

Is it possible to draw a line across all plots in a stackedplot?

12 vues (au cours des 30 derniers jours)
Bryan Conklin
Bryan Conklin le 20 Avr 2020
Commenté : Ameer Hamza le 22 Avr 2020
figure;
chans = 10;
for subplotN=1:chans-1 %plot first set of time-series
x = 1:2841;
y(:,subplotN) = randn(2841,1)*50;
end
y(:,subplotN+1) = randn(1,2841)*1e6;
stackedplot(x,y)
Is it possible to draw vertical lines across all stackedplots like in the figure below?

Réponse acceptée

Ameer Hamza
Ameer Hamza le 20 Avr 2020
Modifié(e) : Ameer Hamza le 20 Avr 2020
I am not sure if there is any direct option, but you can use annotation() to draw a line on the figure window such that it appears on the axes at correct locations. Following code shows an example
figure;
chans = 10;
for subplotN=1:chans-1 %plot first set of time-series
x = 1:2841;
y(:,subplotN) = randn(2841,1)*50;
end
y(:,subplotN+1) = randn(1,2841)*1e6;
s = stackedplot(x,y);
pos = s.Position;
xlims = s.xlim;
line_locations = [500 1000 1500 2000 2500];
line_locations_norm = interp1(xlims, cumsum(pos([1 3])), line_locations);
for i=1:numel(line_locations_norm)
annotation('line', ...
[line_locations_norm(i) line_locations_norm(i)], ...
[pos(2) pos(2)+pos(4)], ...
'Color', 'r', ...
'LineWidth', 1);
end
  4 commentaires
Bryan Conklin
Bryan Conklin le 22 Avr 2020
Thanks Ameer! I was able to modify that approach to end up with the subplot I needed.
Ameer Hamza
Ameer Hamza le 22 Avr 2020
Glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by