Fill/patch with different colors
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Leon Marquardt
am 3 Mär. 2021
Beantwortet: Walter Roberson
am 3 Mär. 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 Kommentar
Mathieu NOE
am 3 Mär. 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]')
Akzeptierte Antwort
Walter Roberson
am 3 Mär. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

