|
1 |
| -import os |
2 | 1 | import sys
|
3 | 2 |
|
4 | 3 | import numpy as np
|
5 | 4 |
|
| 5 | +import pandas |
6 | 6 | import matplotlib.pyplot as plt
|
7 | 7 |
|
8 | 8 | # The following is needed to register the axes
|
|
11 | 11 | from astropy.visualization import LogStretch
|
12 | 12 | from astropy.visualization.mpl_normalize import ImageNormalize
|
13 | 13 |
|
14 |
| -norm = ImageNormalize(vmin=0., vmax=1000, stretch=LogStretch()) |
| 14 | +if len(sys.argv) != 2: |
| 15 | + print("Example usage: python example_taxi.py yellow_tripdata_2016-05.csv") |
| 16 | + print("You can get the data at: http://www.nyc.gov/html/tlc/html/about/trip_record_data.shtml") |
| 17 | + sys.exit(1) |
15 | 18 |
|
16 |
| -ax = plt.subplot(1, 1, 1, aspect='equal', projection='scatter_density') |
| 19 | +filename = sys.argv[1] |
17 | 20 |
|
18 |
| -xmin = -8240227.037 |
19 |
| -ymin = 4974203.152 |
20 |
| -xmax = -8231283.905 |
21 |
| -ymax = 4979238.441 |
| 21 | +print("Reading file (this typically takes 10-20 seconds)...") |
| 22 | +df = pandas.read_csv(filename, usecols=['dropoff_longitude', 'dropoff_latitude']).dropna(axis=0) |
| 23 | +x = df['dropoff_longitude'] |
| 24 | +y = df['dropoff_latitude'] |
22 | 25 |
|
23 |
| -if not os.path.exists('taxi.npz'): |
24 |
| - print("You need to run the convert_nyc.py script first") |
25 |
| - sys.exit(1) |
| 26 | +print("Done reading file, making plot") |
| 27 | + |
| 28 | +norm = ImageNormalize(vmin=0., vmax=1000, stretch=LogStretch()) |
| 29 | + |
| 30 | +ax = plt.subplot(1, 1, 1, projection='scatter_density') |
| 31 | + |
| 32 | +xmin = -74.15 |
| 33 | +xmax = -73.75 |
| 34 | +ymin = 40.62 |
| 35 | +ymax = 40.85 |
26 | 36 |
|
27 |
| -arrays = np.load('taxi.npz') |
28 |
| -x = arrays['x'] |
29 |
| -y = arrays['y'] |
| 37 | +aspect = 1 / np.cos(np.radians(0.5 * (ymin + ymax))) |
30 | 38 |
|
31 |
| -ax.rasterized_scatter(x, y, colormap='plasma', norm=norm) |
| 39 | +ax.scatter_density(x, y, cmap='plasma', norm=norm) |
32 | 40 | ax.set_xlim(xmin, xmax)
|
33 | 41 | ax.set_ylim(ymin, ymax)
|
34 |
| -ax.set_aspect('equal') |
| 42 | +ax.set_xlabel |
| 43 | +ax.set_aspect(aspect) |
35 | 44 |
|
36 | 45 | plt.show()
|
0 commit comments