A Choropleth Map is a map composed of colored polygons. It is used to represent spatial variations of a quantity.
A Choropleth map is a map that is made up of coloured polygons and is used to show the spatial variations of a quantity.
Scatterplot maps are scatterplots that have latitude and longitude instead of x and y axes.
There are different map projections.
Maps can be animated using a sequential value such as year.
Mapbox provides a rich interface with different themes, layers and zoom levels.
px.choropleth(gapminder, locations = 'iso_alpha', color = 'pop')
locations. If mapping countries, the three-letter ISO format can be used for the
locationargument. If using country names you also need to set the
locationmodeto the column containing the country names.
px.choropleth(gapminder, locationmode = 'country names', locations = 'country', color = 'pop')
select a column containing data to be displayed using
color. The data can be discrete or continuous variables
Animation frames can be used to show how values change over years by setting the
px.choropleth(gapminder, locationmode = 'country names', locations = 'country',\ color = 'lifeExp', animation_frame ='year')
layoutattribute has a
geosubattribute where you can set various geographic attributes.
dir method on a figure object will show the available methods.
Here are some of them: (excluding
‘bgcolor’, ‘center’, ‘coastlinecolor’, ‘coastlinewidth’, ‘countrycolor’, ‘countrywidth’, ‘domain’, ‘figure’, ‘fitbounds’, ‘framecolor’, ‘framewidth’, ‘lakecolor’, ‘landcolor’, ‘lataxis’, ‘lonaxis’, ‘oceancolor’, ‘on_change’, ‘parent’, ‘plotly_name’, ‘pop’, ‘projection’, ‘resolution’, ‘rivercolor’, ‘riverwidth’, ‘scope’, ‘showcoastlines’, ‘showcountries’, ‘showframe’, ‘showlakes’, ‘showland’, ‘showocean’, ‘showrivers’, ‘showsubunits’, ‘subunitcolor’, ‘subunitwidth’, ‘to_plotly_json’, ‘uirevision’, ‘update’, ‘visible’
fig.layout.geo.bgcolor='yellow' # to set the background colour / oceans fig.layout.geo.framecolor='blue' # to set the frame colour fig.layout.geo.showframe=False # to remove the rectangular frame fig.layout.geo.showcountries = True # show country borders for which there is no data fig.layout.geo.landcolor = 'white' # This sets the colour for countries which have no data fig.layout.geo.countrycolor = '' # to set colours of country borders fig.layout.geo.coastlinecolor = '' # colour of coastlines fig.layout.geo.projection.type = 'natural earth' # to set a different map projection fig.layout.geo.lataxis.range = [-54, 8] # to limit the vertical range of the axis to focus in on some countries fig.layout.geo.lonaxis.range = [-20, 20] #limit the horizontal range of the axis
Sometimes the variable that the colour is mapped to might have a long name or a name you might want to edit on the map.
fig.layout.coloraxis.colorbar.title = ''
The default scope of a choropleth map is the ‘world’ but you can set the scope to a continent using one of
'north america', or
The Default is
projection is set to
'albers usa', which forces
You can use the
fig.layout.geo.lataxis.range (to limit the vertical range of the graph) and
fig.layout.geo.lonaxis.range (to limit the horizontal range of the graph) to focus more on particular countries.
Longitude is the measurement east or west of the prime meridian. Longitude is measured by imaginary lines that run around the Earth vertically (up and down) and meet at the North and South Poles. These lines are known as meridians. Each meridian measures one arcdegree of longitude. The distance around the Earth measures 360 degrees. See The National Geographic article.
You can set the
scope parameter to a continent (a lowercase string such as ‘europe’ or ‘asia’ )if you want to focus in on a particular continent instead of the default
You could also use the
fig.layout.geo.lonaxis.range to focus in on smaller vertical and horizontal ranges.
The tip of South America is between 45 and 60 degrees South. Ireland’s latitude is approximately between 45 and 60 degrees North while it’s longitude is between approximately 15 degrees West and 0 (the Prime Meridian). Germany’s longitude is between 0 and 15 degrees East.
To focus in on a smaller vertical range, set the latitude range using a minus for South. To focus in on a smaller horizontal range, set the longitude range using a minus for West.
# from 15 degrees South to 60 North fig.layout.geo.lataxis.range = [-15, 60] # from 30 degrees west to 30 degrees East fig.layout.geo.lonaxis.range = [-30, 30]
At the Equator, the vertical meridians are as far away from each other as posible but at the North and South poles the vertical meridians are as close to each other as possible. This gives a more rectangular shape as you approach the equator because a unit of longitude is nearly the same as a unit of latitude. The proportions are completely different though as you approach the poles. The rectangles there begin to approximate triangles.
When the earth is drawn on a flat rectangle the shape will appear somewhat distorted. There are different map projections that can be used. While none are perfect, you can decide on the tradeoff between accuracy in the shape, area, relative position etc.
Plotly Express has a
projection parameter in it’s map functions that takes a string.
Here are the options from the docs (
'azimuthal equal area',
'conic equal area',
You could instead set the map projection by setting a value using the
Can create a callback that links a dropdown or other selection component with a map chart.