Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Pandas
  • Seaborn
  • Matplotlib
  • Altair
  • Bokeh
  • Data Analysis
  • R
  • Machine Learning Math
  • Machin Learning
  • Deep Learning
  • Deep Learning Projects
  • NLP
  • Computer vision
  • Data science
  • Deep learning interview question
  • Machin Learning Interview question
Open In App
Next Article:
Choropleth Maps using Plotly in Python
Next article icon

Choropleth Maps using Plotly in Python

Last Updated : 05 Nov, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Plotly is a Python library that is very popular among data scientists to create interactive data visualizations. One of the visualizations available in Plotly is Choropleth Maps.  Choropleth maps are used to plot maps with shaded or patterned areas which are proportional to a statistical variable. They are composed of colored polygons. They are used for representing spatial variations of a quantity.

To create them, we require two main types of inputs -              

  • Geometric information -
    • this can be a GeoJSON file (here each feature has an id or some identifying value in properties, or
    • this can be built-in geometries of plotly - US states and world countries
  • A list of values with feature identifier as index

Syntax - plotly.express.choropleth((data_frame=None, lat=None, lon=None, locations=None, locationmode=None, geojson=None, color=None, scope=None, center=None, title=None, width=None, height=None)

Parameters:

  • lat = this value is used to position marks according to latitude on a map
  • long = this value is used to position marks according to longitude on a map
  • locations = this value is interpreted according to locationmode and mapped to longitude/latitude.
  • locationmode = one of ‘ISO-3’, ‘USA-states’, or ‘country names’. this determines the set of locations used to match entries in locations to regions on the map.
  • geojson = contains a Polygon feature collection, with IDs, which are references from locations
  • color = used to assign color to marks
  • scope = possible values - 'world', 'usa', 'europe', 'asia', 'africa', 'north america', or 'south america'`Default is `'world' unless projection is set to 'albers usa', which forces 'usa'
  • center = sets the center point of the map

Example:

Python3
# code for creating choropleth map of USA states # import plotly library import plotly  # import plotly.express module # this module is used to create entire figures at once import plotly.express as px  # create figure fig = px.choropleth(locationmode="USA-states", color=[1], scope="usa")  fig.show() 

Output:

A choropleth map can be used to highlight or depict specific areas. The implementation of achieving such functionality is given below.

Example:

Python3
#code for representing states of USA #pass list of states in locations #list will have two-letter abbreviations of states fig = px.choropleth(locations=["CA","TX","NY"], locationmode="USA-states", color=[1,2,3], scope="usa")  fig.show() 

Output:

In this example, we will take a dataset of US-states and create a choropleth map for US Agriculture Exports by USA in 2011.

Dataset Link - Click here

Example:

Python3
#import libraries import pandas as pd import plotly.express as px  #import data data = pd.read_csv('2011_us_ag_exports.csv')  # create choropleth map for the data # color will be the column to be color-coded # locations is the column with sppatial coordinates fig = px.choropleth(data, locations='code',                     locationmode="USA-states", color='total exports', scope="usa")  fig.show() 

Output:


Next Article
Choropleth Maps using Plotly in Python

D

devanshigupta1304
Improve
Article Tags :
  • Python
  • Python-Plotly
Practice Tags :
  • python

Similar Reads

    Carpet Plots using Plotly in Python
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. Plotly is an interactive visualization libra
    3 min read
    Bar chart using Plotly in Python
    Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. Plotly is an interactive visualization librar
    4 min read
    Carpet Contour Plot using Plotly in Python
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    2 min read
    Polar Charts using Plotly in Python
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    2 min read
    Bubble chart using Plotly in Python
    Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. Plotly is an interactive visualization librar
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences