Density Map

A density map plot is a geographic visualization that connects data points with a heatmap on a geographic map using latitude and longitude coordinates or locations. The heatmap is ideal for visualizing the density of data across geographic areas.

Density map plots are appropriate when the dataset contains geographic coordinates (latitude and longitude) or locations that represent individual points on a map. density_map visualizes data using detailed map tiles. For visualizing individual points, use scatter_geo or scatter_map.

What are density map plots useful for?

  • Geographic density: They are excellent for showing the density of individual geographic locations on a map.
  • Detailed geographic context: Density map plots provide a rich and detailed way to visualize geographic data with map tile features.

Examples

A basic density map plot

Visualize geographic density by passing longitude and latitude column names to the lon and lat arguments. It’s recommended to set the initial zoom level and center coordinates for better visualization based on the data. Click and drag on the resulting map to pan and zoom.

import deephaven.plot.express as dx

# Load the outages dataset
outages_table = dx.data.outages()

# Create a density map showing concentration of outages
# Zoom and center are set for better initial view
density_map_plot = dx.density_map(
    outages_table,
    lat="Lat",
    lon="Lon",
    zoom=9,
    center=dx.data.OUTAGE_CENTER
)

Adjust the density radius

Control how spread out the density visualization appears using the radius argument.

import deephaven.plot.express as dx

# Load the outages dataset
outages_table = dx.data.outages()

# Use a larger radius for a more diffuse heatmap
# Zoom and center are set for better initial view
density_map_plot = dx.density_map(
    outages_table,
    lat="Lat",
    lon="Lon",
    radius=10,
    zoom=9,
    center=dx.data.OUTAGE_CENTER
)

Customize the color scale

Change the color scale using the color_continuous_scale argument.

import deephaven.plot.express as dx

# Load the outages dataset
outages_table = dx.data.outages()

# Use a different color scale
# Zoom and center are set for better initial view
density_map_plot = dx.density_map(
    outages_table,
    lat="Lat",
    lon="Lon",
    color_continuous_scale=["yellow", "orange", "red"],
    zoom=9,
    center=dx.data.OUTAGE_CENTER
)

Change map style

Use different base map styles with the map_style argument. The default style is dependent on the theme.

import deephaven.plot.express as dx

# Load the outages dataset
outages_table = dx.data.outages()

# Change the map style for different tiles
# Zoom and center are set for better initial view
density_map_plot = dx.density_map(
    outages_table,
    lat="Lat",
    lon="Lon",
    map_style="open-street-map",
    zoom=9,
    center=dx.data.OUTAGE_CENTER
)

API Reference

Create a density_map plot

Returns: DeephavenFigure A DeephavenFigure that contains the density_map figure

ParametersTypeDefaultDescription
tableTable |
DataFrame
A table to pull data from.
latstr |
None
NoneA column name to use for latitude values.
lonstr |
None
NoneA column name to use for longitude values.
zstr |
None
NoneA column name to use for z values.
hover_namestr |
None
NoneA column that contains names to bold in the hover tooltip.
labelsdict[str, str] |
None
NoneA dictionary of labels mapping columns to new labels.
color_continuous_scalelist[str] |
None
NoneA list of colors for a continuous scale
range_colorlist[float] |
None
NoneA list of two numbers that form the endpoints of the color axis
color_continuous_midpointfloat |
None
NoneA number that is the midpoint of the color axis
radiusint30The radius of each point.
opacityfloat |
None
NoneOpacity to apply to all markers. 0 is completely transparent and 1 is completely opaque.
zoomfloat |
None
0The zoom level of the map. 0 is the whole world, and higher values zoom in closer.
centerdict[str, float] |
None
NoneA dictionary of center coordinates. The keys should be 'lat' and 'lon' and the values should be floats that represent the lat and lon of the center of the map.
map_stylestr |
None
NoneThe style of the map. Defaults to None, which uses the theme's default. If a str, one of 'basic', 'carto-darkmatter', 'carto-darkmatter-nolabels', 'carto-positron', 'carto-positron-nolabels', 'carto-voyager', 'carto-voyager-nolabels', 'dark', 'light', 'open-street-map', 'outdoors', 'satellite', 'satellite-streets', 'streets', 'white-bg'.
titlestr |
None
NoneThe title of the chart
templatestr |
None
NoneThe template for the chart.
unsafe_update_figureCallable<function default_callback>An update function that takes a plotly figure as an argument and optionally returns a plotly figure. If a figure is not returned, the plotly figure passed will be assumed to be the return value. Used to add any custom changes to the underlying plotly figure. Note that the existing data traces should not be removed. This may lead to unexpected behavior if traces are modified in a way that break data mappings.