Fill/patch with different colors
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Leon Marquardt
le 3 Mar 2021
Réponse apportée : Walter Roberson
le 3 Mar 2021
Hi there, i want to display my behavioral data as filled areas over time.
x = [1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8];
y = [0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0];
a = fill(x,y,'b');
a.FaceAlpha = 0.1;
xlabel('time [s]')
Something simple like that. However, i want for example the second and third area to be the same color because they are the same behavior and the first and last be something different. How do i do that ? I already read through the patch/fill manual but didn't figured it out. A huge thank you in advance!
1 commentaire
Mathieu NOE
le 3 Mar 2021
hello
this is it :
x = [1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8];
y = [0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0];
colour = [1 1 1 1 0 0 0 0 0 0 0 0 2 2 2 2 ];
a = fill(x,y,colour);
a.FaceAlpha = 0.5;
xlabel('time [s]')
Réponse acceptée
Walter Roberson
le 3 Mar 2021
It might be possible if you played around with FaceVertexCData and similar properties for long enough, but it would be easier if you were to change how you draw.
x = [1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8];
y = [0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0];
vertices = [x(:), y(:)];
faces = [
1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16;
];
groups = [1 2 2 1];
cmap = parula(numel(unique(groups)));
colors = cmap(groups,:);
patch('vertices', vertices, 'Faces', faces, 'FaceColor', 'flat', 'FaceVertexCData', colors, 'CDataMapping', 'direct', 'FaceAlpha', 0.1);
xlabel('time [s]')
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Polygons 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!

