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
| Parameters | Type | Default | Description |
|---|---|---|---|
| table | Table | DataFrame | A table to pull data from. | |
| lat | str | None | None | A column name to use for latitude values. |
| lon | str | None | None | A column name to use for longitude values. |
| z | str | None | None | A column name to use for z values. |
| hover_name | str | None | None | A column that contains names to bold in the hover tooltip. |
| labels | dict[str, str] | None | None | A dictionary of labels mapping columns to new labels. |
| color_continuous_scale | list[str] | None | None | A list of colors for a continuous scale |
| range_color | list[float] | None | None | A list of two numbers that form the endpoints of the color axis |
| color_continuous_midpoint | float | None | None | A number that is the midpoint of the color axis |
| radius | int | 30 | The radius of each point. |
| opacity | float | None | None | Opacity to apply to all markers. 0 is completely transparent and 1 is completely opaque. |
| zoom | float | None | 0 | The zoom level of the map. 0 is the whole world, and higher values zoom in closer. |
| center | dict[str, float] | None | None | A 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_style | str | None | None | The 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'. |
| title | str | None | None | The title of the chart |
| template | str | None | None | The template for the chart. |
| unsafe_update_figure | Callable | <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. |