1

I have a dataset looking like this:

1 38.7114 -7.92482 16.4375 0.2 ...

I'd like to make a 3D scatter plot. I've done it using cartesian coordinates. How I can do it using geographic coordinates? Any hint?

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import sys
from mpl_toolkits.basemap import Basemap

ID=[]
Latitude=[]
Longitude=[]
Depth=[]
cluster1='data1'
with open(cluster1) as f:
    lines = f.readlines()
    for line in lines:
        items = line.strip().split()
        lat = float(items[1])
        lon = float(items[2])
        dep = float(items[3])
        mag = float(items[4])
        Latitude.append(lat)
        Longitude.append(lon)
        Depth.append(dep)
        ID.append(mag)


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
p = ax.scatter(Longitude, Latitude, Depth, c=ID, marker='o')

ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')
ax.set_zlabel('Depth (km)')
ax.invert_zaxis()
cb = fig.colorbar(p,label='Magnitude')
plt.savefig('plot1.png')

enter image description here

evtoh
  • 444
  • 3
  • 10
  • 21
CatarinaCM
  • 1,145
  • 3
  • 13
  • 21
  • check out cartopy: http://scitools.org.uk/cartopy/docs/latest/index.html – reptilicus Aug 22 '16 at 17:02
  • These questions might be a good starting point - http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates , http://gis.stackexchange.com/questions/120679/equations-to-convert-from-global-cartesian-coordinates-to-geographic-coordinates , http://gis.stackexchange.com/questions/73728/how-do-i-convert-longitude-latitude-to-a-3d-geocentric-x-y-z-coordinate – user812786 Aug 23 '16 at 12:21

0 Answers0