Modelling a Day of Trips in 3D

In a Survey Design and Analysis course that I'm taking currently, we recently read a paper from Cynthia Chen et al. on "The promises of big data and small data for travel behavior (aka human mobility) analysis" (DOI: [10.1016/j.trc.2016.04.005](http:dx.doi.org/10.1016/j.trc.2016.04.005, behind paywall). Since plenty of other people have talked about the advantages and disadvantages of big data, I'm only going to touch on a data visualization technique I thought was pretty cool. Chen et al. created a 3D illustration of trip segments, tours, and daily activity/travel patterns. I decided to write up a short python script so that I could see my own day in 3D.

Taking a look at the code,

import numpy as np  # Need genfromtxt and arrays
import seaborn as sns  # Needed to make plots pretty
import matplotlib.pyplot as plt  # 
from mpl_toolkits.mplot3d import Axes3D


def trip3d(fname='data.csv', locations='normwal'):
    longit = np.genfromtxt(fname, delimiter=',', usecols=0)
    latit = np.genfromtxt(fname, delimiter=',', usecols=1)
    time = np.genfromtxt(fname, delimiter=',', usecols=2)
    place = np.genfromtxt(fname, delimiter=',', usecols=3, dtype='S')
    print(place)
    print(type(place[1]))

    # Setting up the plot
    fig = plt.figure()
    ax = fig.gca(projection='3d')  # make it 3D!
    ax.plot(longit, latit, time, label='3D-Illustration of Trips')  # Plotting

    # Some labels
    ax.set_xlabel('Longitude')
    ax.set_ylabel('Latitude')
    ax.set_zlabel('Time')

    # Going through every entry plotting the text at the point where you arrive
    for i in range(len(place)):
        ax.text(longit[i], latit[i], time[i], place[i].decode('UTF-8'))

    ax.legend()
    plt.show()

if __name__ == '__main__':
    trip3d()

So there's definitely a bit of work to do to polish this up, but the code creates a plot which I saved as the svg below. The longitude and latitude numbers don't make sense because I made up everything in the plot below.

3D Illustration of Daily Trip