How do I plot colors for different mesh elements using trimesh?
Mostra commenti meno recenti
I have a 2D mesh that I want to plot, and it seems like trimesh() may be the best function for doing so. However, I'm not clear on the capabilities of this function with regard to colors. Is there a way to fill each mesh element with a different color according to some pre-defined array of element colors? Is there any way to make this work with a colorbar?
Thanks.
Edit: To be more specific, my mesh is already stored in the data structure expected by the trimesh() function: A triangle connectivity matrix, and a set of x and y points for the nodes. I have a value stored in a separate vector for each element in the connectivity matrix that I want to be able to plot as a color for that element.
3 Commenti
Dyuman Joshi
il 4 Nov 2023
Spostato: Dyuman Joshi
il 4 Nov 2023
"Is there a way to fill each mesh element with a different color according to some pre-defined array of element colors?"
%Example
%Sample data
[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
Specifying color for each element -
%% Black
%predefined array of element colors #1
C1 = zeros([size(Z),3]);
mesh(X,Y,Z,C1)
surf(X,Y,Z,C1)
%% Random colors
%predefined array of element colors #1
C2 = rand([size(Z) 3]);
mesh(X,Y,Z,C2)
surf(X,Y,Z,C2)
%% Red
%predefined array of element colors #1
C3 = zeros([size(Z) 3]);
C3(:,:,1) = 1;
mesh(X,Y,Z,C3)
surf(X,Y,Z,C3)
Garrett West
il 4 Nov 2023
Spostato: Dyuman Joshi
il 4 Nov 2023
Dyuman Joshi
il 4 Nov 2023
Spostato: Dyuman Joshi
il 4 Nov 2023
In that case -
%Example
%Sample data
[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
%Triangulation object
T = delaunay(X,Y);
%trisurf plot
h = trisurf(T, X, Y, Z);
%Values for Color
C = rand([size(Z) 3]);
%Update the color data of the trisurf plot
h.CData = C;
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






