fname=r"/Users/Sukhbinder/Downloads/Takeout/Location History/LocationHistory.json" # Import pandas import pandas as pd import numpy as np # Import matplotlib and Basemap import matplotlib.pyplot as plt #from mpl_toolkits.basemap import Basemap # Set iPython to display visualization inline %matplotlib inline raw = pd.read_json(fname) #pd.io.json.read_json(fname) raw.tail(5) df = raw['locations'].apply(pd.Series) df.tail(5) df['latitude'] = df['latitudeE7'] * 0.0000001 # Create a list from the longitude column, multiplied by -E7 df['longitude'] = df['longitudeE7'] * 0.0000001 df.tail(5) df.head(5) lat=df['longitude'].values*np.pi/180.0 long=df['latitude'].values*np.pi/180.0 x = np.cos(long)*np.cos(lat) y = np.cos(long)*np.sin(lat) z = np.sin(long) import vtk class VtkPointCloud: def __init__(self, zMin=-10.0, zMax=10.0, maxNumPoints=1e6): self.maxNumPoints = maxNumPoints self.vtkPolyData = vtk.vtkPolyData() self.clearPoints() mapper = vtk.vtkPolyDataMapper() mapper.SetInput(self.vtkPolyData) mapper.SetScalarRange(zMin, zMax) mapper.SetScalarVisibility(1) self.vtkActor = vtk.vtkActor() self.vtkActor.SetMapper(mapper) self.vtkActor.GetProperty().SetPointSize(4) self.vtkActor.GetProperty().SetColor(1,0,0) def addPoint(self, point): if self.vtkPoints.GetNumberOfPoints() < self.maxNumPoints: pointId = self.vtkPoints.InsertNextPoint(point[:]) self.vtkDepth.InsertNextValue(point[2]) self.vtkCells.InsertNextCell(1) self.vtkCells.InsertCellPoint(pointId) self.vtkCells.Modified() self.vtkPoints.Modified() self.vtkDepth.Modified() def clearPoints(self): self.vtkPoints = vtk.vtkPoints() self.vtkCells = vtk.vtkCellArray() self.vtkDepth = vtk.vtkDoubleArray() self.vtkDepth.SetName('DepthArray') self.vtkPolyData.SetPoints(self.vtkPoints) self.vtkPolyData.SetVerts(self.vtkCells) self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth) self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') cldpnts= VtkPointCloud() for i in range(len(x)): cldpnts.addPoint([x[i],y[i],z[i]]) ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) WIDTH=640 HEIGHT=480 renWin.SetSize(WIDTH,HEIGHT) # create a renderwindowinteractor iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren.SetBackground(0.48, 0.48, 0.48) # create source source = vtk.vtkEarthSource() source.SetOnRatio = 2 # mapper for original earth coneMapper1 = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: coneMapper1.SetInput(source.GetOutput()) else: coneMapper1.SetInputConnection(source.GetOutputPort()) # actor for earth actor1 = vtk.vtkActor() actor1.SetMapper(coneMapper1) actor1.GetProperty().SetColor(0, 0, 0) # (R,G,B) actor1.GetProperty().SetSpecular = 0.45 actor1.GetProperty().SetSpecularPower = 5 actor1.SetBackfaceCulling = True # add points actor on the earth # assign actor to the renderer ren.AddActor(cldpnts.vtkActor) ren.AddActor(actor1) # enable user interface interactor iren.Initialize() renWin.Render() iren.Start() # Create a figure of size (i.e. pretty big) fig = plt.figure(figsize=(20,10)) # Create a map, using the Gall–Peters projection, map = Basemap(projection='gall', # with low resolution, resolution = 'l', # And threshold 100000 area_thresh = 100000.0, # Centered at 0,0 (i.e null island) lat_0=0, lon_0=0) # Draw the coastlines on the map map.drawcoastlines() # Draw country borders on the map map.drawcountries() # Fill the land with grey map.fillcontinents(color = '#888888') # Draw the map boundaries map.drawmapboundary(fill_color='#f4f4f4') # Define our longitude and latitude points x,y = map(df['longitude'].values, df['latitude'].values) # Plot them using round markers of size 6 map.plot(x, y, 'ro', markersize=6) # Show the map plt.show()