XData and YData from area chart

9 vues (au cours des 30 derniers jours)
Chad Greene
Chad Greene le 2 Nov 2021
Commenté : Star Strider le 2 Nov 2021
I'm using the area function to create a stacked area chart of hundreds of time series. After plotting my data via
h = area(t,Y);
I'd like to access the coordinates of all of the filled areas using
h(1).XData
h(1).YData
however, I'm surprised to find that h.XData and h.YData return the input data I gave it (time,Y) rather than the coordinates of the plotted objects.
Is there a way to access the plotted coordinates of the filled objects?

Réponse acceptée

Star Strider
Star Strider le 2 Nov 2021
Add (cumsum) ‘Y’ row-wise to get the coordinates —
t = 1:10;
Y = randi(9, 10, 3)
Y = 10×3
1 7 5 8 8 8 3 4 2 2 1 6 6 2 7 2 1 2 3 4 7 7 5 2 5 7 5 2 4 8
Ycoordinates = cumsum(Y,2)
Ycoordinates = 10×3
1 8 13 8 16 24 3 7 9 2 3 9 6 8 15 2 3 5 3 7 14 7 12 14 5 12 17 2 6 14
figure
h = area(t,Y);
grid
.
  2 commentaires
Chad Greene
Chad Greene le 2 Nov 2021
Yes, of course! Thanks Star Strider for the elegant and well-explained solution!
Star Strider
Star Strider le 2 Nov 2021
As always, my pleasure!
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by