Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Plot Geographical Data on a Map Using Python Plotly

  • Jayant VermaJayant Verma
  • December 10, 2020
  • Python Programming Examples
Plot Geographical Data on a Map Using Python Plotly

In this tutorial, we will learn how to plot geographical data on a map using Python Plotly. For this demonstration, we’ll plot COVID-19 cases from ourworldindata.org dataset.

Steps to Plot Geographical Data on a Map in Python

Let’s get started.

1. Import the required libraries

Let’s start with importing the necessary libraries. We need to import the following two libraries:

  1. Pandas
  2. Plotly.express
import pandas as pd
import plotly.express as px

Now we can move to the next step, that is downloading the dataset.

2. Download and read the dataset

To download and load the dataset, use the following piece of code.

!wget https://covid.ourworldindata.org/data/owid-covid-data.csv

Output :

Download Dataset
Download Dataset

Read the CSV dataset in Python using the pandas read_csv method:

df = pd.read_csv('owid-covid-data.csv')
df.head()
Dataset
Dataset

3. Plotting the COVID-19 Dataset on a Map

Now we can use Plotly to plot the data from the dataset above.

We are plotting a Choropleth Map. It is a map which uses differences in shading, colouring, or the placing of symbols within predefined areas to indicate the average values of a particular quantity in those areas.

We are going to plot the number of new cases each day. Plotly lets us do that through animations.

Here’s the code to plot the colors and shades on the map:

fig = px.choropleth(df, locations="iso_code",
                    color="new_cases",
                    hover_name="location",
                    animation_frame="date",
                    title = "Covid Cases plotted using Plotly",                 color_continuous_scale=px.colors.sequential.PuRd)


fig["layout"].pop("updatemenus")
fig.show()

Output :

Feb
Feb
Plot Geographical Data - April
April
Plot Geographical Data in Python Plotly - September
September

The output shows how the map looks over three different months of the year. We can see that the virus was spreading rapidly in China in the month of February, in USA in the month of April and in India in the month of September.

You can also hover over any region of the map and view the number of new cases.

Plotly animations make it convenient to visualize time series data.

4. Complete code to Plot Geographical Data using Python Plotly

The complete code for this section in given below :

import pandas as pd
import plotly.express as px

#download dataset
!wget https://covid.ourworldindata.org/data/owid-covid-data.csv

#import dataset
df = pd.read_csv('owid-covid-data.csv')

#plot
fig = px.choropleth(df, locations="iso_code",
                    color="new_cases",
                    hover_name="location",
                    animation_frame="date",
                    title = "Covid Cases plotted using Plotly",                 color_continuous_scale=px.colors.sequential.PuRd)


fig["layout"].pop("updatemenus")
fig.show()

6. Plotting COVID-19 Asia Data

You can also set the scope of the map to Asia. Let’s see how to plot geographical data for the content of Asia.

To set the scope of the plot to Asia, set the parameter ‘scope‘ to ‘asia’.

import pandas as pd
import plotly.express as px

#download dataset
!wget https://covid.ourworldindata.org/data/owid-covid-data.csv

#import dataset
df = pd.read_csv('owid-covid-data.csv')

#select entries with the continent as asia
df = df[df.continent == 'Asia']

#plot
fig = px.choropleth(df, locations="iso_code",
                    color="new_cases",
                    hover_name="location",
                    animation_frame="date",
                    title = "Daily new COVID cases",
                    scope ='asia',  color_continuous_scale=px.colors.sequential.PuRd)

fig["layout"].pop("updatemenus")
fig.show()

Output :

Covid cases in Asia

This video shows new cases of COVID-19 for each day with the help of animation.

Conclusion

This tutorial was on plotting geographical data in Python Plotly. We plotted data from the Covid-19 dataset using Plotly in python. To learn about other types of maps that Plotly lets you create, read their official documentation.

Jayant Verma
Jayant Verma
Articles: 26
Virtual Environments in Python – Easy Installation and Setup
Previous Post Virtual Environments in Python - Easy Installation and Setup
Next Post Unicode In Python - The unicodedata Module Explained
Unicode In Python – The unicodedata Module Explained

Related Posts

How to Calculate Distance Between Two Points in Python

How to Calculate Distance Between Two Points in Python

  • November 26, 2026
CIFAR 10 Dataset: Load and Use in Python

CIFAR 10 Dataset: Load and Use in Python

  • November 24, 2026
Maximum A Posteriori Estimation in Python

Maximum A Posteriori Estimation in Python

  • November 24, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.