Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot 3d cartesian grid with python [closed]

Tags:

python

numpy

I have just started to learn python and I encounter a problem while trying to produce a figure.

I have a large set of points (~ 42000) with X-Y-Z coordinates and with several variable associated (temperature, water content ...) I would like to plot all this stuff in one graph but it appears to be impossible with my level of python knowledge.. All these points are situated on a cartesian regular grid. So I wanted to produce a meshgrid grid with numpy but the I'm stuck .. Basically I want to transfrom 1D vector (X,Y,Z and T let's say) into a 3d grid with interpolated data. Is that possible ?

Could you please help me ?

like image 829
user3473016 Avatar asked Dec 07 '22 02:12

user3473016


2 Answers

This is complicated data to view, so I think you'll need a tool designed to make viewing of 3D data easy, and MayaVi is an excellent option for this.

Here's an example,

enter image description here

And the most important aspect of this is that it's highly interactive, so using the mouse I can easily grab and move around the slice planes. and even tilt them to explore the data volumetric data (which is very useful, as in this case we can see it's mostly red on the inside, which we couldn't have guessed from just the surface):

enter image description here

Here's the code, which is just a slightly modified version of this:

from mayavi import mlab
import numpy as np

x, y, z = np.ogrid[-2:2:20j, -2:2:20j, -2:2:20j]
s = np.sin(x*y*z + x + y*z)/(x*y*z + x + y*z)

mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(s),
                            plane_orientation='x_axes',
                            slice_index=20,
                        )
mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(s),
                            plane_orientation='y_axes',
                            slice_index=20,
                        )
mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(s),
                            plane_orientation='z_axes',
                            slice_index=20,
                        )
mlab.outline()
mlab.show()
like image 197
tom10 Avatar answered Dec 30 '22 06:12

tom10


Check matplotlib, it is a nice and well-illustrated python plotting module, you should find what you need !

A first example

Specific 3D example

like image 35
floppy12 Avatar answered Dec 30 '22 08:12

floppy12