Plotly Scatter Plot

This example reviews plotting a scatter plot from a GeoDataFrame using plotly.

[1]:
import mapped
import geopandas as gpd
import plotly
mapped.__version__, gpd.__version__, plotly.__version__
[1]:
('20.04.0', '0.7.0', '4.6.0')

First load some example point data.

[2]:
from mapped.example_data import mad_points
points = mad_points()
points.head()
[2]:
number letter geometry
1 73.522015 A POINT (-9945192.638 5333669.463)
2 59.605820 A POINT (-9952134.036 5321688.221)
3 52.676887 A POINT (-9937860.167 5328515.553)
6 22.133990 B POINT (-9948386.303 5310253.324)
7 34.937765 A POINT (-9963868.554 5319452.429)
[3]:
points.plotly_scatter(
    color='letter',
    size='number',
    text='letter',
)
GeoDataFrame.plotly_scatter(*, zoom='auto', mapbox_style=None, margins=0, figuretype=None, fig=None, size=None, color=None, suppress_hover=False, mode=None, **kwargs)

Make a scatter point map in a plotly FigureWidget.

Parameters:
  • gdf (geopandas.GeoDataFrame) – The areas to plot.
  • zoom (‘auto’ or int or float) – Sets the initial zoom level for the map, up to 20.
  • mapbox_style (str, optional) – Sets the style for the basemap tiles. Totally free options include “carto-positron”, “stamen-terrain”, “stamen-toner”, “open-street-map”, possibly others. Options from the set {‘basic’,’streets’,’outdoors’,’light’,’dark’,’satellite’, ‘satellite-streets’} will load vector tiles from MapBox, which requires a token to be set. This defaults to “carto-positron” if no mapbox token is set, or ‘basic’ if a token is available.
  • margins (int, optional) – Set margins on the figure.
  • figuretype (class, optional) – Which plotly figure class to use, defaults to plotly.go.FigureWidget.
  • fig (plotly.go.Figure or plotly.go.FigureWidget) – An existing figure, to which the new trace(s) will be appended.
  • size (numeric) – Either a name of a column in gdf, or a pandas Series or array_like object. Values from this column or array_like are used to assign marker sizes. Missing values will not be plotted at all.
  • color (str or int or Series or array-like) – Either a name of a column in gdf, or a pandas Series or array_like object. Values are used to assign color to markers.
  • text (str or int or Series or array-like) – Either a name of a column in gdf, or a pandas Series or array_like object. Values appear in the figure as text labels.
  • hover_name (str or int or Series or array-like) – Either a name of a column in gdf, or a pandas Series or array_like object. Values appear in bold in the hover tooltip.
  • hover_data (list of str or int, or Series or array-like) – Either names of columns in gdf, or pandas Series, or array_like objects Values appear as extra data in the hover tooltip.
  • opacity (float) – Value between 0 and 1. Sets the opacity for markers.
  • size_max (int (default 20)) – Set the maximum mark size when using size.
  • title (str) – The figure title.
  • width (int (default None)) – The figure width in pixels.
  • height (int (default 600)) – The figure height in pixels.
  • **kwargs – Other keyword arguments are passed through to the plotly.express.scatter_mapbox constructor, allowing substantial further customization of the resulting figure.
Returns:

Return type:

plotly.go.FigureWidget