How to re-size Choropleth maps - Python
Last Updated :
24 Apr, 2025
In this article, we are going to learn how to create resizable maps using different libraries in Python.
Choropleth maps are a type of thematic map that displays divided regions or territories shaded or patterned in relation to a specific data variable. In Python, choropleth maps can be created using various libraries, such as matplotlib, plotly, geopandas.
Choropleth maps are a powerful tool to display data over a geographical region. In Python, the most commonly used libraries for creating choropleth maps are geopandas and plotly. To resize choropleth maps in Python, we can use the layout() function in plotly or matplotlib to adjust the figure size. Choropleth maps are commonly used in various fields, such as geography, economics, and public health, to visualize and analyze spatial patterns and trends in data. Here we are discussing three methods through which we can create resizable choropleth maps.
Prerequisites
Install the required libraries using the pip command given below.
pip install geopandas
pip install matplotlib
pip install plotly
Choropleth map using the GeoPandas library
In this example, we first load the required libraries which are geopandas and matplotlib. Load the naturalearth_lowres dataset and then, we create a choropleth map of the countries by plotting the gdp_md_est column, which represents the estimated gross domestic product. We use the OrRd color map and include a legend. Next, we resize the plot by getting the current figure object with plt.gcf(), setting its size using the set_size_inches() method, and displaying the plot using plt.show(). In this case, we set the figure size to 12 inches wide and 6 inches tall. we can adjust the size to fit your specific needs. we can resize that map using the components which are showing in the output.
Python
# import library for create choropleth map
import geopandas as gpd
import matplotlib.pyplot as plt
# Load the data and create a choropleth map
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.plot(column='gdp_md_est',
cmap='OrRd', legend=True)
# Resize the plot
fig = plt.gcf()
fig.set_size_inches(12, 6)
# show map
plt.show()
Output :
Choropleth map using the Plotly library
In this, we import the Plotly library. This code uses the plotly.graph_objects module to create a Choropleth map of the United States, displaying data for three states (California, Texas, and New York) with corresponding values (1, 2, and 3) represented by color. we can resize that map using the components which are showing in the output.
Python
# import ploty libraray
import plotly.graph_objects as go
# create figure using fig method
fig = go.Figure(data=go.Choropleth(
locations=['CA', 'TX', 'NY'],
z=[1, 2, 3],
locationmode='USA-states',
colorscale='Viridis',
))
# Resize the code using
# update layout figure method
fig.update_layout(
title_text='GeeksforGeeks',
geo=dict(scope='usa', showlakes=True,
lakecolor='rgb(85,173,240)'),
width=500,
height=500,
)
#show map
fig.show()
Output :
Choropleth map using the Plotly Express Library
The below code is using the Plotly Express library to create a choropleth map that visualizes the voting results of an election we can resize that map using the components which are showing in the output.
Python
# import ploty.express libraray
import plotly.express as px
# Load data
df = px.data.election()
# Create choropleth map
fig = px.choropleth(df,
locations="district",
color="Bergeron",
hover_name="district",
range_color=[0, 50],
color_continuous_scale="agsunset")
# Resize map by height and width
fig.update_layout(height=400,
width=600)
# Show map
fig.show()
Output :
Similar Reads
Choropleth Maps using Plotly in Python
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. T
3 min read
Python Plotly - How to set colorbar position for a choropleth map?
In this article, we will learn how to set colorbar position for a choropleth map in Python using Plotly. Color bar are gradients that go from bright to dark or the other way round. They are great for visualizing data that go from low to high, like income, temperature, or age. Choropleth maps are use
2 min read
Pgmagick resize() method - Python
The resize() function is an inbuilt function in the Pgmagick library which is used to resize an image. The function returns the true value on success. Syntax: resize('widthxheight') Parameters: This function accepts the string of width and height formatted as 'widthxheight' which depicts the dimensi
1 min read
How to resize Image in Python - Tkinter?
Python provides multiple options for building GUI (Graphical User Interface) applications. Among them, Tkinter is one of the most widely used and simplest options. It comes bundled with Python and serves as a standard interface to the Tk GUI toolkit.However, Tkinter alone does not provide support fo
2 min read
How to change figure size in Plotly in Python
In this article, we will discuss how we can change the figure size in Plotly in Python. Let's firstly take about Plotly in Python. Plotly  Python library provides us with an interactive open-source Plotly library that can support over 40 unique chart types that cover a wide list of statistical, fin
4 min read
How to reverse a Colormap using Matplotlib in Python?
Prerequisites: Matplotlib Matplotlib has many built-in Colormaps. Colormaps are nothing but the dictionary which maps the integer data/numbers into colors. Colormaps are used to differentiate or distinguish the data in a particular plot. The reason to use the colormaps is that it is easier for human
6 min read
Python PIL | Image.resize() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files,
4 min read
How to set a Seaborn chart figure size?
Seaborn is a Python data visualization library based on Matplotlib. It is used to draw attractive and informative statistical graphics. To adjust the figure size of the seaborn plot we will use the subplots function of matplotlib.pyplot. Examples to change the figure size of a seaborn axes matplotli
2 min read
Pandas.reset_option() function in Python
Pandas have an options system that lets us customize some aspects of its behavior, display-related options being those the user is most likely to adjust. Let us see how to reset the value of a specified option back to its default value. reset_option() Syntax : pandas.reset_option(pat)Â Parameters :
2 min read
How to make Choropleth Maps with Labels using Mapbox API
Choropleth maps are interesting visualization tools that use the intensity of a color to represent aggregate data for different locations within their bounding boxes. They are a lot of fun and are fairly easy to make using the Plotly library. Choropleth maps are powerful data visual representations
4 min read