I need to plot a scalar field that is structured in a 3D grid as the one that follows:
import numpy as np
from mayavi import mlab
dt = 10
X,Y,Z = np.mgrid[0:dt,0:dt,0:dt]
F = X**2+Y**2+Z**2
test = mlab.figure(size = (1024,768), bgcolor = (1,1,1), fgcolor = (0, 0, 0))
sf = mlab.pipeline.scalar_field(X,Y,Z,F)
vl = mlab.pipeline.volume(sf)
mlab.outline()
mlab.axes()
mlab.title('Can not change font size for this title')
mlab.xlabel('Only end ticks')
mlab.ylabel('No major ticks')
I would like to do so in Python since I simulate many datasets in this language and I would like to be able to visualize them quickly as I perform sensitivities in my simulation parameters.
Mayavi seemed to offer pretty standard routines for scientific 3d plotting. However, when it comes to communicate these plots in publications, very basic plot customizations are not available such as major and minor ticks in the axes. Also, those very basic features that are supported do not even work properly to date (e.g. see example in font size bug and here).
Is there any decent and easy to use scientific 3D plotting library in Python? I have tried learning vtk but the website examples seem to be obsolete (e.g. volume rendering example that fails to run, I tried editing many lines of code to make it work without luck) and others seem to agree that the documentation is lacking.
By decent scientific plotting library I mean the following:
You should try matplotlib, if you haven't done so already. It's not difficult to use meshgrid
and contour
or contourf
(you'll find scripts on the web easily enough) to plot data on structured grids. It's even possible to plot on unstructured grids (Check this out: https://grantingram.wordpress.com/plotting-2d-unstructured-data-using-free-software/ )
It has your characteristics of a "decent" scientific plotting library.
EDIT: When you say '3D' plotting, I assumed you wanted a plot of a function of 2 variables, so that its graph is 3D.
If, however, you have data depending on 3 space variables, I assume you want the ability to display cut planes and such. Then I recommend you output your data to files and use a proper visualization package such as ParaView (which uses VTK) or TecPlot (non-free). You can automate the visualization pipeline through scripting (I believe ParaView supports Python scripting).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With