Julia counterparts to slice and contourslice in Matlab

plotting

#1

For making plots like this:
iso2mesh,
I think slice and contourslice functions in Matlab/Octave are very helpful. But are there equivalent functions in Julia to do this kind of plots? I know PyPlot or Matplotlib is not very good on rendering real 3D plots. Please let me know if these 3D plot functions have been implemented in Julia. Thanks.


#2

You might consider saving your data using WriteVTK.jl and then visualizing with Paraview. That provides slices and much more. Paraview takes some effort to learn, but I find it preferable to Matlab for some volume visualizations, and especially good for volume+time (like CFD). Not the Julia solution you ask for, but nicely compatible with Julia.


GLVisualize
#3

@Ralph_Smith Thank you for replying! What is the advantage of using VTK and then Paraview compared to uisng HDF5 and then Mayavi or Paraview? I forgot to mention my data is originally saved in HDF5 format which may work naturally with external 3D visualization programs, but I am more interested in using some commands in Julia so that I can make plots in Jupyter notebook and such.


#4

This sounds like the kind of thing that you would use Glvisualize.jl for.


#5

Yeah you can use GLVisualize it :slight_smile:


Code:

Sorry for any inconveniences, I just right now fixed up GLPlot to work with the newest GLVisualize, so it might still act buggy.
It would be possible to add this code sample as a visualization style.

IJulia integration is not great right now, since the interactivity will mostly be missing :confused:
It’s implemented for the Plots.jl package, since it is quite static to begin with, but not for GLVisualize/GLPlot, since these packages are pretty meaningless without interaction. But in principle it’s also straight forward to grab the image from GLVisualize/GLPlot and display it inlined in the notebook.


Visualize 3D slices of an 3D image volume?
#6

Very nice! Good to see the progress here. It took me a while to discover that I needed to click the tiny button on the right border to bring up the slider controls. I hope you (@sdanisch) will have time to make another narrated video about this general class of displays; I really needed this earlier one to make sense of the other GLVisualize examples. Also, a pointer to the example dataset would be helpful (I’m not sure the one I found is as good). I wasn’t sure which packages needed to be checked out to master to make this work, so I just iterated until success.

VTK is simpler (but the explanation for my suggestion is that Paraview didn’t handle HDF when I first learnt to use it).


#7

I’d be interested in a PyPlot solution to this as well. I see that Paraview or other packages are better for publication-ready figures, but I couldn’t find a way to use them for interactive plotting or in IJulia notebooks.

Anyway, @i2000s, what I typically use in matlab for these kinds of plots is surf(X,Y,Z,C) where X,Y,Z define a 3D surface and C is an array of intensity values for each surface patch. We should in principle be able to use PyPlot for this, since matplotlib has similar functionality. See this discussion here.

This is how far I got (sorry this code is using our package jInv to generate the mesh, but I think you get the idea)

using jInv.Mesh
using PyPlot
M = getRegularMesh([0 1 0 1 0 1], [ 5 6 7])
xc = getNodalGrid(M);
XYZ = reshape(xc,tuple([M.n+1;3]...))
slice = 2;
surf(XYZ[:,:,slice,1], XYZ[:,:,slice,2], XYZ[:,:,slice,3],facecolors=XYZ[:,:,slice,3])

This throws an error since facecolors (an array of Floats) must somewhat be converted to a color. Maybe we can use PyPlot.ColorMap for that, but I’m stuck. Does anyone have an idea?


#8

A little belated here, but I will put in a plug for my favorite scientific plotting library of all time, MathGL. I have a Julia wrapper for it here.

MathGL appears to have methods for just what you’re wanting to do (e.g., the Dens3D function)

Happy plotting!

Lewis