Choropleth Map
Chart overview
Choropleth maps use color gradients to represent statistical values across defined geographic regions such as countries, states, or counties.
Key points
- Each region is shaded according to its data value, creating a powerful visualization for comparing metrics across geography.
- These maps are widely used in demographics, election results, epidemiology, and economic analysis.
- When creating choropleths, consider using appropriate color scales and potentially logarithmic transformations for skewed data.
Create a Choropleth Map with your data using AI — no coding required.
Python Tutorial
How to create a choropleth map in Python
Use the full tutorial for implementation details, troubleshooting, and chart variations in matplotlib, seaborn, and plotly.
How to Create a Heatmap in PythonInteractive Visualization
Loading interactive chart...
This is an interactive choropleth map. You can zoom, pan, and hover over elements for details.
Create This Chart Now
Generate publication-ready choropleth maps with AI in seconds. No coding required – just describe your data and let AI do the work.
View example prompt
"Create an interactive world choropleth map showing 'GDP per Capita by Country' for 2023. Generate realistic data for 50+ countries ranging from $800 (lowest) to $85,000 (highest). Use a logarithmic Viridis color scale to handle the skewed distribution. Add hover tooltips showing country name, GDP per capita formatted as currency, and world ranking. Include a color bar legend with properly formatted tick labels ($1K, $10K, $100K). Use 'natural earth' projection, show coastlines but hide frame. Add a descriptive title and data source annotation."
How to create this chart in 30 seconds
Upload Data
Drag & drop your Excel or CSV file. Plotivy securely processes it in your browser.
AI Generation
Our AI analyzes your data and generates the Choropleth Map code automatically.
Customize & Export
Tweak the design with natural language, then export as high-res PNG, SVG or PDF.
Newsletter
Get one weekly tip for better choropleth maps
Join researchers receiving concise Python plotting techniques to improve chart clarity and reduce revision cycles.
Python Code Example
import plotly.express as px
import pandas as pd
import numpy as np
# Generate sample GDP per capita data for demonstration
countries = [
'United States', 'China', 'Japan', 'Germany', 'United Kingdom', 'France',
'India', 'Italy', 'Brazil', 'Canada', 'Russia', 'South Korea', 'Spain',
'Australia', 'Mexico', 'Indonesia', 'Netherlands', 'Saudi Arabia',
'Turkey', 'Switzerland', 'Poland', 'Sweden', 'Belgium', 'Argentina',
'Ireland', 'Norway', 'Israel', 'Austria', 'Nigeria', 'South Africa',
'Egypt', 'United Arab Emirates', 'Thailand', 'Singapore', 'Malaysia',
'Chile', 'Finland', 'Greece', 'Portugal', 'Czech Republic', 'Romania',
'New Zealand', 'Vietnam', 'Bangladesh', 'Philippines', 'Pakistan',
'Kazakhstan', 'Colombia', 'Peru', 'Ukraine', 'Cuba', 'Morocco',
'Kenya', 'Ghana', 'Ethiopia', 'Tanzania', 'Uganda', 'Sudan',
'Cameroon', 'Ivory Coast', 'Senegal', 'Zambia', 'Zimbabwe', 'Mozambique',
'Angola', 'Botswana', 'Namibia', 'Madagascar', 'Malawi', 'Rwanda',
'Burundi', 'Somalia', 'Libya', 'Tunisia', 'Algeria', 'Jordan',
'Lebanon', 'Syria', 'Iraq', 'Yemen', 'Oman', 'Qatar', 'Kuwait',
'Bahrain', 'Cyprus', 'Luxembourg', 'Monaco', 'Andorra', 'Malta',
'Iceland', 'Estonia', 'Latvia', 'Lithuania', 'Slovakia', 'Slovenia',
'Croatia', 'Bosnia', 'Serbia', 'Montenegro', 'Albania', 'Macedonia',
'Bulgaria', 'Hungary', 'Denmark', 'Belarus', 'Moldova', 'Georgia',
'Armenia', 'Azerbaijan', 'Uzbekistan', 'Turkmenistan', 'Kyrgyzstan',
'Tajikistan', 'Mongolia', 'Nepal', 'Bhutan', 'Sri Lanka', 'Myanmar',
'Laos', 'Cambodia', 'Papua New Guinea', 'Fiji', 'Solomon Islands',
'Vanuatu', 'Samoa', 'Tonga', 'Kiribati', 'Marshall Islands', 'Palau'
]
# Generate realistic GDP per capita values (in USD)
np.random.seed(42)
gdp_values = []
for country in countries:
# Assign GDP per capita based on economic regions
if country in ['Luxembourg', 'Monaco', 'Switzerland', 'Ireland', 'Norway', 'Singapore']:
gdp = np.random.uniform(60000, 120000)
elif country in ['United States', 'Qatar', 'Kuwait', 'United Arab Emirates', 'Denmark', 'Netherlands', 'Sweden', 'Australia']:
gdp = np.random.uniform(45000, 70000)
elif country in ['Germany', 'Canada', 'United Kingdom', 'France', 'Japan', 'South Korea', 'New Zealand', 'Austria', 'Belgium']:
gdp = np.random.uniform(35000, 50000)
elif country in ['China', 'Russia', 'Brazil', 'Mexico', 'Turkey', 'Poland', 'Spain', 'Italy']:
gdp = np.random.uniform(10000, 35000)
elif country in ['India', 'Indonesia', 'Thailand', 'Malaysia', 'South Africa', 'Egypt', 'Nigeria']:
gdp = np.random.uniform(2000, 10000)
elif country in ['Pakistan', 'Bangladesh', 'Philippines', 'Vietnam', 'Kenya', 'Ghana', 'Ethiopia']:
gdp = np.random.uniform(500, 3000)
else:
gdp = np.random.uniform(1000, 15000)
gdp_values.append(gdp)
# Create DataFrame
df = pd.DataFrame({
'Country': countries,
'GDP_per_Capita': gdp_values
})
# Create choropleth map with logarithmic color scale
fig = px.choropleth(
df,
locations='Country',
locationmode='country names',
color='GDP_per_Capita',
hover_name='Country',
hover_data={'GDP_per_Capita': ':,.0f'},
color_continuous_scale='Viridis',
range_color=(100, 120000),
title='World GDP per Capita (Logarithmic Scale)',
labels={'GDP_per_Capita': 'GDP per Capita (USD)'},
projection='natural earth'
)
# Update layout for better appearance
fig.update_layout(
geo=dict(
showframe=False,
showcoastlines=True,
coastlinecolor='LightGray',
landcolor='White',
oceancolor='LightBlue',
lakecolor='LightBlue'
),
margin=dict(l=0, r=0, t=50, b=0),
height=600
)
# Add color bar with proper formatting and logarithmic scale
fig.update_coloraxes(
colorbar=dict(
title='GDP per Capita (USD)',
tickformat=',.0f',
thickness=20,
len=0.7
),
colorscale='Viridis',
cmin=100,
cmax=120000,
colorbar_tickmode='array',
colorbar_tickvals=[100, 1000, 10000, 100000],
colorbar_ticktext=['$100', '$1,000', '$10,000', '$100,000']
)
# Show the figure
fig.show()
# Optional: Save the figure as an HTML file
# fig.write_html("world_gdp_per_capita.html")
# Optional: Save the figure as a static image (requires additional packages)
# fig.write_image("world_gdp_per_capita.png")
# Display summary statistics
print("\nGDP per Capita Summary Statistics:")
print(df['GDP_per_Capita'].describe())
# Display top 10 countries by GDP per capita
print("\nTop 10 Countries by GDP per Capita:")
top_10 = df.nlargest(10, 'GDP_per_Capita')
for idx, row in top_10.iterrows():
print(f"{row['Country']}: ${row['GDP_per_Capita']:,.0f}")
# Display bottom 10 countries by GDP per capita
print("\nBottom 10 Countries by GDP per Capita:")
bottom_10 = df.nsmallest(10, 'GDP_per_Capita')
for idx, row in bottom_10.iterrows():
print(f"{row['Country']}: ${row['GDP_per_Capita']:,.0f}")
fig.show()
# END-OF-CODEOpens the Analyze page with this code pre-loaded and ready to execute
Common Use Cases
- 1Visualizing population density by region
- 2Election results by state or county
- 3COVID-19 case rates by country
- 4Economic indicators across nations
Pro Tips
Use diverging color scales for data with meaningful midpoint
Consider logarithmic scales for highly skewed data
Add hover information for exact values
Frequently asked questions
When should you use a choropleth map?
Choropleth maps use color gradients to represent statistical values across defined geographic regions such as countries, states, or counties. Each region is shaded according to its data value, creating a powerful visualization for comparing metrics across geography. Common applications include visualizing population density by region, election results by state or county, and cOVID-19 case rates by country.
Which Python libraries can create a choropleth map?
A choropleth map can be built in Python with folium, geopandas, and plotly — folium, pandas for quick plots straight from a DataFrame, and Plotly for interactive hover, zoom, and web sharing. In Plotivy you describe the figure and it writes the folium code for you.
Can I make a choropleth map without writing Python code?
Yes. Describe the choropleth map you need in plain language and upload your dataset — Plotivy's AI writes the Python code and renders a publication-ready figure. You still get the full, editable folium source, so nothing is locked in a black box.
What are best practices for a clear choropleth map?
Use diverging color scales for data with meaningful midpoint. Consider logarithmic scales for highly skewed data.
Long-tail keyword opportunities
High-intent chart variations
Library comparison for this chart
folium
Useful in specialized workflows that complement core Python plotting libraries for choropleth-map analysis tasks.
geopandas
Good for quick exploratory drafts directly from DataFrame operations before polishing in matplotlib or plotly.
plotly
Best for interactive hover, zoom, and web sharing when collaborators need to inspect values directly from choropleth-map figures.
Scientific Chart Selection Cheat Sheet
Not sure whether to use a Violin Plot, Box Plot, or Ridge Plot? Download our single-page reference mapping the most-used scientific chart types, exactly when to use them, and the core Matplotlib/Seaborn functions.