Location Data Visualization with Python
3 min readMar 6, 2018
Mapbox has recently released Mapboxgl-Jupyter python library for Geographic data visualization within Jupyter notebooks. I tried it over the weekend and I believe it provides beautiful visualization tools and a convenient way to visualize Geographic data.
It works well with pandas DataFrame. For example, you can create Geojson file out a dataframe by using df_to_geojson function and passing the dataframe :
df_to_geojson(df, filename=’parking_violations.geojson’,
properties=[‘issue_date’, ‘violation_’, ‘fine’, ‘issuing_ag’],
lat=’lat’, lon=’lon’, precision=3)
Now, to visualize your location data, you can use MapViz() or CircleViz().
# Generate data breaks and color stops from colorBrewer
color_breaks = mapclassify.Natural_Breaks(df['fine'], k=8, initial=0).bins
color_stops = create_color_stops(color_breaks, colors='YlGnBu')# Create the viz from the dataframe
viz = CircleViz('parking_violations.geojson',
access_token=x,
height='400px',
color_property = "fine",
color_stops = color_stops,
center = (-75.059,40.058),
zoom = 12,
below_layer = 'waterway-label')viz.show()