Member-only story

Find your country on a Map

Python Coding
2 min readOct 20, 2024

--

import plotly.express as px

country = input("Enter the country name: ")
data = {
'Country': [country],
'Values': [100] }
fig = px.choropleth(
data,
locations='Country',
locationmode='country names',
color='Values',
color_continuous_scale='Inferno',
title=f'Country Map Highlighting {country}')
fig.show()

Here’s an explanation of the provided code:

1. import plotly.express as px

  • Plotly Express: A high-level Python visualization library that is part of the Plotly ecosystem. It allows for easy creation of interactive plots.
  • px: This alias is used to access functions from the Plotly Express module conveniently.

2. country = input("Enter the country name: ")

  • This line prompts the user to enter a country name (e.g., “India”, “United States”).

3. data = {'Country': [country], 'Values': [100]}

  • A dictionary is created with two keys: Country (holding the user-input country) and Values (holding the value 100). This serves as data to be used for generating the map.

4. fig = px.choropleth(...)

  • This line creates a choropleth map, a type of map where…

--

--

Python Coding
Python Coding

Written by Python Coding

Learn python tips and tricks with code I Share your knowledge with us to help society. Python Quiz: https://www.clcoding.com/p/quiz-questions.html

No responses yet