Fill/patch with different colors
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Leon Marquardt
il 3 Mar 2021
Risposto: Walter Roberson
il 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 Commento
Mathieu NOE
il 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]')
Risposta accettata
Walter Roberson
il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Polygons in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

