john smith optional
john smith optional

Reputation: 31

Matplotlib 3D hypocenter plot, reading xyz values from .txt file

I am trying to learn python by doing. I have real world xy (lat long dd) coordinates and z (km below surface) values for about 500,000 earthquakes (hypocenter) from M 0.1 to 2.0. I chopped the data down to 10 rows of xyz values in a .txt tab delimited table. I want to plot the data in a 3d scatter plot rotatable box in matplotlib. I can use basic commands to read the data and the format looks fine. I am not clear if I need to read the data into a list or array for mpl to read and plot the data. Do I need to create an array at all?

I then want to plot the subsurface location of an oil well, given the xyz coordinates of vertices along the well bore (about 40 positions), do I need to create a polyline?. This data has the same general coordiantes (to be evaluated further) as some of the hypcenters. Which set of data should be the plot, and which should be the subplot? Also, I am unclear as to the "float" that I need given the 6 to 7 decimal places of he xy lat long coordinates, and the 2 decimal z coordinates.

Upvotes: 3

Views: 3537

Answers (1)

Joe Kington
Joe Kington

Reputation: 284770

Matplotlib is a poor choice for this, actually. It doesn't allow true 3D plotting, and it won't handle the complexity (or number of points in 3D) that you need. Have a look at mayavi instead.

Incidentally, it sounds like you're doing microseismic? (I'm a geophysist, as well, for whatever it's worth.)

As a quick example:

from enthought.mayavi import mlab
import numpy as np

# Generate some random hypocenters
x, y, z, mag = np.random.random((4, 500))

# Make a curved well bore...
wellx, welly, wellz = 3 * [np.linspace(0, 1.5, 10)]
wellz =  wellz**2

# Plot the hypocenters, colored and scaled by magnitude
mlab.points3d(x, y, z, mag)

# Plot the wellbore
mlab.plot3d(wellx, welly, wellz, tube_radius=0.1)

mlab.show()

enter image description here

As far as reading in your data goes, it sounds like it should be as simple as:

x, y, z = np.loadtxt('data.txt').T

What problems have you run in to?

Upvotes: 4

Related Questions