API reference¶
geoplotlib module¶
-
geoplotlib.
add_layer
(layer)¶ Add a layer
Parameters: layer – a BaseLayer object
-
geoplotlib.
clear
()¶ Remove all existing layers
-
geoplotlib.
convexhull
(data, col, fill=True, point_size=4)¶ Convex hull for a set of points
Parameters: - data – points
- col – color
- fill – whether to fill the convexhull polygon or not
- point_size – size of the points on the convexhull. Points are not rendered if None
-
geoplotlib.
delaunay
(data, line_color=None, line_width=2, cmap=None, max_lenght=100)¶ Draw a delaunay triangulation of the points
Parameters: - data – data access object
- line_color – line color
- line_width – line width
- cmap – color map
- max_lenght – scaling constant for coloring the edges
-
geoplotlib.
dot
(data, color=None, point_size=2, f_tooltip=None)¶ Create a dot density map
Parameters: - data – data access object
- color – color
- point_size – point size
- f_tooltip – function to return a tooltip string for a point
-
geoplotlib.
geojson
(filename, color='b', linewidth=1, fill=False, f_tooltip=None)¶ Draw features described in geojson format (http://geojson.org/)
Parameters: - filename – filename of the geojson file
- color – color for the shapes. If callable, it will be invoked for each feature, passing the properties element
- linewidth – line width
- fill – if fill=True the feature polygon is filled, otherwise just the border is rendered
- f_tooltip – function to generate a tooltip on mouseover. It will be invoked for each feature, passing the properties element
-
geoplotlib.
graph
(data, src_lat, src_lon, dest_lat, dest_lon, linewidth=1, alpha=220, color='hot')¶ Create a graph drawing a line between each pair of (src_lat, src_lon) and (dest_lat, dest_lon)
Parameters: - data – data access object
- src_lat – field name of source latitude
- src_lon – field name of source longitude
- dest_lat – field name of destination latitude
- dest_lon – field name of destination longitude
- linewidth – line width
- alpha – color alpha
- color – color or colormap
-
geoplotlib.
hist
(data, cmap='hot', alpha=220, colorscale='sqrt', binsize=16, show_tooltip=False, scalemin=0, scalemax=None, f_group=None)¶ Create a 2D histogram
Parameters: - data – data access object
- cmap – colormap name
- alpha – color alpha
- colorscale – scaling [lin, log, sqrt]
- binsize – size of the hist bins
- show_tooltip – if True, will show the value of bins on mouseover
- scalemin – min value for displaying a bin
- scalemax – max value for a bin
- f_group – function to apply to samples in the same bin. Default is to count
-
geoplotlib.
inline
(width=900)¶ display the map inline in ipython
Parameters: width – image width for the browser
-
geoplotlib.
kde
(data, bw, cmap='hot', method='hist', scaling='sqrt', alpha=220, cut_below=None, clip_above=None, binsize=1, cmap_levels=10)¶ Kernel density estimation visualization
Parameters: - data – data access object
- bw – kernel bandwidth (in screen coordinates)
- cmap – colormap
- method – if kde use KDEMultivariate from statsmodel, which provides a more accurate but much slower estimation. If hist, estimates density applying gaussian smoothing on a 2D histogram, which is much faster but less accurate
- scaling – colorscale, lin log or sqrt
- alpha – color alpha
- cut_below – densities below cut_below are not drawn
- clip_above – defines the max value for the colorscale
- binsize – size of the bins for hist estimator
- cmap_levels – discretize colors into cmap_levels levels
-
geoplotlib.
markers
(data, marker, f_tooltip=None, marker_preferred_size=32)¶ Draw markers
Parameters: - data – data access object
- marker – full filename of the marker image
- f_tooltip – function to generate a tooltip on mouseover
- marker_preferred_size – size in pixel for the marker images
-
geoplotlib.
savefig
(fname)¶ Launch geoplotlib, saves a screeshot and terminates
-
geoplotlib.
scatter
(data, color=None, point_size=2, f_tooltip=None)¶ Deprecated: use dot
-
geoplotlib.
set_bbox
(bbox)¶ Set the map bounding box
Parameters: bbox – a BoundingBox object
-
geoplotlib.
set_map_alpha
(alpha)¶ Alpha color of the map tiles
Parameters: alpha – int between 0 and 255. 0 is completely dark, 255 is full brightness
-
geoplotlib.
set_smoothing
(smoothing)¶ Enables OpenGL lines smoothing (antialiasing)
Parameters: smoothing – smoothing enabled or disabled
-
geoplotlib.
set_window_size
(w, h)¶ Set the geoplotlib window size
Parameters: - w – window width
- h – window height
-
geoplotlib.
shapefiles
(fname, f_tooltip=None, color=None, linewidth=3, shape_type='full')¶ Load and draws shapefiles
Parameters: - fname – full path to the shapefile
- f_tooltip – function to generate a tooltip on mouseover
- color – color
- linewidth – line width
- shape_type – either full or bbox
-
geoplotlib.
show
()¶ Launch geoplotlib
-
geoplotlib.
tiles_provider
(tiles_provider)¶ Set the tile provider
Parameters: tiles_provider – either one of the built-in providers [‘watercolor’, ‘toner’, ‘toner-lite’, ‘mapquest’, ‘darkmatter’,’positron’] or a custom provider in the form {‘url’: lambda zoom, xtile, ytile: ‘someurl’ % (zoom, xtile, ytile), ‘tiles_dir’: ‘mytiles’, ‘attribution’: ‘my attribution’ })
-
geoplotlib.
voronoi
(data, line_color=None, line_width=2, f_tooltip=None, cmap=None, max_area=10000.0, alpha=220)¶ Draw the voronoi tesselation of the points
Parameters: - data – data access object
- line_color – line color
- line_width – line width
- f_tooltip – function to generate a tooltip on mouseover
- cmap – color map
- max_area – scaling constant to determine the color of the voronoi areas
- alpha – color alpha
geoplotlib.layers module¶
-
class
geoplotlib.layers.
BaseLayer
¶ Base class for layers
-
bbox
()¶ Return the bounding box for this layer
-
draw
(proj, mouse_x, mouse_y, ui_manager)¶ This method is called at every frame, and typically executes BatchPainter.batch_draw()
Parameters: - proj – the current Projector object
- mouse_x – mouse x
- mouse_y – mouse y
- ui_manager – the current UiManager
-
invalidate
(proj)¶ This method is called each time layers need to be redrawn, i.e. on zoom. Typically in this method a BatchPainter is instantiated and all the rendering is performed
Parameters: proj – the current Projector object
-
on_key_release
(key, modifiers)¶ Override this method for custom handling of keystrokes
Parameters: - key – the key that has been released
- modifiers – the key modifiers
Returns: True if the layer needs to call invalidate
-
geoplotlib.utils module¶
-
class
geoplotlib.utils.
DataAccessObject
(dict_or_df)¶ This class wraps data into a dict-like object
-
static
from_dataframe
(df)¶ Loads data from a pandas DataFrame
Parameters: df – dataframe Returns: a DataAccessObject
-
head
(n)¶ Return a DataAccessObject containing the first n rows
Parameters: n – number of rows Returns: DataAccessObject
-
keys
()¶ Returns: the keys (field names)
-
rename
(mapping)¶ Rename fields
Parameters: mapping – a dict in the format {‘oldkey1’: ‘newkey1’, ...}
-
values
()¶ Returns: the values (field values)
-
where
(mask)¶ Parameters: mask – boolean mask Returns: a DataAccessObject with a subset of rows matching mask
-
static
-
geoplotlib.utils.
epoch_to_str
(epoch, fmt='%Y-%m-%d %H:%M:%S')¶ Convert a unix timestamp into date string
Parameters: - epoch – unix timestamp
- fmt – date format
Returns: formatted date from timestamp
-
geoplotlib.utils.
haversine
(lon1, lat1, lon2, lat2)¶ Distance between geodesic coordinates http://www.movable-type.co.uk/scripts/latlong.html
Parameters: - lon1 – point 1 latitude
- lat1 – point 1 longitude
- lon2 – point 1 latitude
- lat2 – point 2 longitude
Returns: distance in meters between points 1 and 2
-
geoplotlib.utils.
read_csv
(fname)¶ Read a csv file into a DataAccessObject
Parameters: fname – filename
geoplotlib.core module¶
-
class
geoplotlib.core.
BatchPainter
¶ - This class batches OpenGL calls. The usage pattern is to instantiate a BatchPainter,
- perform all the drawing and finally render using batch_draw
geoplotlib.colors module¶
-
geoplotlib.colors.
colorbrewer
(values, alpha=255)¶ Return a dict of colors for the unique values. Colors are adapted from Harrower, Mark, and Cynthia A. Brewer. “ColorBrewer. org: an online tool for selecting colour schemes for maps.” The Cartographic Journal 40.1 (2003): 27-37.
Parameters: - values – values
- alpha – color alphs
Returns: dict of colors for the unique values.
-
geoplotlib.colors.
create_set_cmap
(values, cmap_name, alpha=255)¶ return a dict of colors corresponding to the unique values
Parameters: - values – values to be mapped
- cmap_name – colormap name
- alpha – color alpha
Returns: dict of colors corresponding to the unique values