Fill/patch with different colors

12 ビュー (過去 30 日間)
Leon Marquardt
Leon Marquardt 2021 年 3 月 3 日
回答済み: Walter Roberson 2021 年 3 月 3 日
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 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 3 月 3 日
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]')

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 3 日
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 件)

カテゴリ

Help Center および File ExchangePolygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by