marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.03k stars 265 forks source link

Colormap/colors on face background. #1073

Closed ManuGraiph closed 6 months ago

ManuGraiph commented 6 months ago

Hi Marco!

I'm trying to build some FEM-from-scratch implementation using vedo for visualization and class wrapping but i can't manage to get a correct plotting of the cell colors. I'm assigning values to celldata in a mesh and trying to make a heatmap plot with them, but i don't know very well how to use the vedo.show() function or what are its arguments and the output is like showing the colorscale reversed.

I basically have a field in celldata called 'temp' with values and when i call vd.show(mesh) i get this:

vedo

The colorscale, field in celldata, etc get selected automatically and i haven't been able to find any way to modify them.

Any ideas?

Thanks in advance!

marcomusy commented 6 months ago

Hi! There are tons of examples with color mapping:

vedo --search cmap

Eg examples/basic/colormaps.py examples/basic/mesh_coloring.py

something like

mymesh.cmap("jet_r", "temp", vmin=-20, on="cells")
mymesh.add_scalarbar3d("Temperature")

could apply to your case.

ManuGraiph commented 6 months ago

Worked perfect by changing jet_r to jet`, thanks a lot!

A couple questions tho...

  1. How can i change which celldata value (in case i had more than one) is used for the colormap? The second argument ('temp') does that?

  2. For some reason (i run everything on repl, not as a script), vedo plot objects don't seem to 'clean' in the same session if i change something in the mesh definition and run the plot again. For ex. if i plot a mesh object, change the faces and plot it again in the same session, it kinda plots "both". Is there any way to "clear" the vedo.show() plot?. I run a couple custom lines between runs to clear all user vars/functions, but the plot still persists.

Thanks in advance!

marcomusy commented 6 months ago

Worked perfect by changing jet_r to jet`, thanks a lot!

A couple questions tho...

  1. How can i change which celldata value (in case i had more than one) is used for the colormap? The second argument ('temp') does that?

Yes.

  1. For some reason (i run everything on repl, not as a script), vedo plot objects don't seem to 'clean' in the same session if i change something in the mesh definition and run the plot again. For ex. if i plot a mesh object, change the faces and plot it again in the same session, it kinda plots "both". Is there any way to "clear" the vedo.show() plot?. I run a couple custom lines between runs to clear all user vars/functions, but the plot still persists.

Either show().clear() or (best practice):

plt= Plotter()
...
plt.show()  # you call this only once

...
# some loop or callback
   plt.remove("SomeObject").add(my_new_obj)
   plt.render()

you can assign custom names witth my_new_obj.name=""MySphere

ManuGraiph commented 6 months ago

Worked flawless, thanks a lot again!

ManuGraiph commented 6 months ago

Oh, a small little thing i forgot.. It's possible to add to the plot labels for the cells (not the points) with thext from celldata and/or another source?

marcomusy commented 6 months ago

Yes: https://vedo.embl.es/autodocs/content/vedo/vedo/visual.html#PointsVisual.labels