Plot mesh with color

43 views
Skip to first unread message

chuan...@hotmail.com

unread,
Jul 9, 2018, 9:57:00 AM7/9/18
to iso2mesh-users
Hello Qianqian,

Hope this finds you well. I have generated a mesh and want to have a color gradient on the mesh. I have tried to assigned numbers to the 5th column of elem variable, but this gives me a random color, which is distracting. 

Also, I have tried "caxis", it gave me a pretty mesh plot long time ago, but this time, it seems it does not work. 

I have attached my code but somehow the image stack was not uploaded successfully. Please find the stack from this link https://www.dropbox.com/s/0hiezfo3d4ew5zf/0.6_geometry.tif?dl=0

Hope to get some recommendations from you and thank you in advance!

-Chuanyue
FEM_sample.m

Qianqian Fang

unread,
Jul 9, 2018, 1:52:07 PM7/9/18
to iso2mes...@googlegroups.com, chuan...@hotmail.com
hi Chuanyue

not sure what exactly the color gradient you wanted to see on with the mesh, but from reading your code, your current plotmesh line maps the element index (labellist_elem) as the color, which is rather a random label in space.

in order for this to be a gradient, you need to assign each element with a value that varies continuously over space. for example, you can plot the z*y of the centroid of each element using

c0=meshcentroid(node,elem(:,1:4));
plotmesh(node(:,1:3),[elem(:,1:4) c0(:,3).*c0(:,2)],'facealpha','0.7')

alternatively, you can also plot a gradient with a continuously varying nodal value, for example, a y-dir gradient

plotmesh(node(:,[1 2 3 2]),elem(:,1:4),'facealpha','0.7')

typically, I use the element-label for plotting a segmented domain, which is often a piecewise constant domain

 
[nobbx,fcbbx]=meshabox([40 0 0], [160, 120, 60], 10);
[nosp,fcsp]=meshasphere(s0, 5, 1);
[no,fc]=mergemesh(nobbx, fcbbx, nosp, fcsp);

[cfg0.node, cfg0.elem]=s2m(no,fc(:,1:3),1,40,'tetgen',[41 1 1;s0]);

cfg0.seg=cfg0.elem(:,5);

plotmesh(cfg0.node,[cfg0.elem,cfg0.seg],'z<20')
view([0 0 1])

hope this helps.

Qianqian


-Chuanyue
--
You received this message because you are subscribed to the Google Groups "iso2mesh-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iso2mesh-user...@googlegroups.com.
To post to this group, send email to iso2mes...@googlegroups.com.
Visit this group at https://groups.google.com/group/iso2mesh-users.
For more options, visit https://groups.google.com/d/optout.


chuan...@hotmail.com

unread,
Jul 26, 2018, 6:19:51 PM7/26/18
to iso2mesh-users
Hello Qianqian,

Sorry for replying late. The suggestions you provided worked very well. Thank you very much for your help!

BR,
Chuanyue
Reply all
Reply to author
Forward
0 new messages