Patch Multiple Specified Colors
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dwight Schrute III
am 18 Mai 2019
Beantwortet: Hadrien Bériot
am 24 Okt. 2019
Is there a way to create more than one polygon and fill them with different colors specified by the user? I know that with patch function, there is a way to create random colors for them, and there is a way to create just one color for all the polygons, but I don't know how to specify that, for instance, I want the first polygon to be red and the second to be green. For example:
X = [0 0; 0 0; 4 4];
Y = [0 4; 3 7; 0 4];
C = [.25; .75]
p = patch(X,Y,C)
This creates two triangles, with the triangle on top as yellow and the triangle on the bottom as purple. But how do I make it such that the triangle on top is red, and the triangle on the bottom is green? Ideally, this would be accomplished without a loop?
Long story short: I want to be able to apply conditional formatting to a wide array of values. But it seems cumbersome to do them one color at a time.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 18 Mai 2019
The simplest way is probably to define a colormap for the figure.
Try this:
X = [0 0; 0 0; 4 4];
Y = [0 4; 3 7; 0 4];
C = [.25; .75];
colormap([0 1 0; 1 0 0]);
p = patch(X,Y,C);
There are likely a number of differnt ways to do this, depending on the result you want. I encourage you to experiment.
0 Kommentare
Weitere Antworten (1)
Hadrien Bériot
am 24 Okt. 2019
I personally use a random vector
FaceValue = rand(1,size(Element,2))';
patch('Faces',Element','Vertices',Coord','FaceVertexCData',FaceValue,'FaceColor','flat','EdgeColor','k');
colormap(hsv(100))
0 Kommentare
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!