Style a base map
Make a geographic chart easier to read by showing coastlines, countries, land, oceans, lakes, or rivers with chosen colors.
Plotly · Module
fig.update_geos() updates geographic layout properties on a Plotly figure. Use it to control map appearance, positioning, projection, boundaries, and geographic extents.
Call fig.update_geos() to change one or more properties of the figure’s geographic layout, such as map appearance, center, projection, visible boundaries, and axis ranges. It updates the existing layout.geo configuration using the named geographic properties supplied as keyword arguments.
fig.update_geos(...)| Name | Type | Description |
|---|---|---|
**kwargs | varies by layout.geo property | Geographic layout properties, supplied as keyword arguments; examples include bgcolor, center_lat, center_lon, coastlinecolor, coastlinewidth, countrycolor, domain_x, fitbounds, and projection_type. |
The documentation page describes the update method and its geographic properties but does not specify a separate return value.
center_lat to specify the map’s latitude center.center_lon to specify the map’s longitude center.coastlinecolor controls the color used for coastline lines.coastlinewidth controls coastline thickness in pixels and must be nonnegative.countrycolor styles the lines drawn for country boundaries.center_lat, Plotly derives the latitude center from the latitude range.domain_x uses plot-fraction coordinates rather than geographic longitude values.import plotly.graph_objects as go
fig = go.Figure(go.Scattergeo(
lat=[40.7, 51.5], lon=[-74.0, -0.1],
mode="markers", text=["New York", "London"]
))
fig.update_geos(
showcoastlines=True,
showcountries=True,
showland=True,
landcolor="LightGreen",
showocean=True,
oceancolor="LightBlue",
projection_type="natural earth"
)
fig.show()Creates a geographic scatter plot and configures its base map, boundaries, colors, and projection.
Make a geographic chart easier to read by showing coastlines, countries, land, oceans, lakes, or rivers with chosen colors.
Focus the viewport on a chosen latitude and longitude or constrain the displayed latitude and longitude ranges.
Choose an appropriate cartographic representation such as a natural-earth projection.
Automatically fit the geographic view to plotted locations.
fig.update_geos() configure?update_geos is the figure method used to update geographic layout attributes. It accepts keyword arguments corresponding to properties documented for layout.geo, including colors, visibility flags, center, projection, and ranges.
Follow-up: How would you configure more than one geographic subplot? Use the appropriate geo layout container and its domain settings, then target the relevant geographic configuration rather than treating all maps as one plot.
Set center_lat and center_lon to control the map center. The documentation identifies these as numeric properties for the latitude and longitude center, respectively.
Follow-up: How can the visible geographic extent be constrained? Configure the corresponding latitude and longitude axis ranges, while using center values when you also need a controlled focal point.
Use projection_type to select the map projection, and use properties such as showcoastlines, showcountries, landcolor, and oceancolor to control the base-map presentation. These are geographic layout attributes accepted by the update method.
Follow-up: How would you make the map fit plotted locations? Set fitbounds to the documented fitting mode, such as locations, when the figure’s data should determine the displayed bounds.
layout.geocenterprojectionprojection_typefitboundslataxislonaxisScattergeo