Skip to content

Commit 14a5531

Browse files
committed
Fix taxi example [ci skip]
1 parent 9f970c5 commit 14a5531

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

examples/convert_nyc.py

-15
This file was deleted.

examples/example_taxi.py

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import os
21
import sys
32

43
import numpy as np
54

5+
import pandas
66
import matplotlib.pyplot as plt
77

88
# The following is needed to register the axes
@@ -11,26 +11,35 @@
1111
from astropy.visualization import LogStretch
1212
from astropy.visualization.mpl_normalize import ImageNormalize
1313

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)
1518

16-
ax = plt.subplot(1, 1, 1, aspect='equal', projection='scatter_density')
19+
filename = sys.argv[1]
1720

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']
2225

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
2636

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)))
3038

31-
ax.rasterized_scatter(x, y, colormap='plasma', norm=norm)
39+
ax.scatter_density(x, y, cmap='plasma', norm=norm)
3240
ax.set_xlim(xmin, xmax)
3341
ax.set_ylim(ymin, ymax)
34-
ax.set_aspect('equal')
42+
ax.set_xlabel
43+
ax.set_aspect(aspect)
3544

3645
plt.show()

0 commit comments

Comments
 (0)