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 :
How to re-size Choropleth maps – Python
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
Contact Us