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 = 'w3wiki' , geo = dict (scope = 'usa' , showlakes = True , lakecolor = 'rgb(85,173,240)' ), width = 500 , height = 500 , ) #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