Plot your Geographical Data using Plotly and MapBox
Got 5 minutes? Got Python? Want to visualize your data like the image below? Then let’s get into it.
Don’t have coordinate data? You can generate some in less than 5 minutes in this article here: https://rich-gaogle.medium.com/get-coordinates-via-mapboxs-geocoding-api-cbe9b089b4a7?sk=517f6da5a982722d4d25aa00ed432026
Install the relevant libraries and import them
Code

You can grab an access token from: https://docs.mapbox.com/help/getting-started/access-tokens/
We use the px.scatter_mapbox function to create a visualization of the latitude and longitude data provided. Certain visualizations can be used if we provide a mapbox token. Our data here is imported from a repository. If you have your own data you can replace these lines with data of your own. In our visualization, we color each data point by its state and make the point size based on population of that city. The results:
Done! Happy coding.
Code (For copying and pasting)
!pip install pandas;pip install plotly
# Import Libraries
import requests
import json
import pandas as pd
import ssl
MAPBOX_APIKEY=”<insert token here>”
ssl._create_default_https_context = ssl._create_unverified_context
us_cities = pd.read_csv(“https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")
px.set_mapbox_access_token(MAPBOX_APIKEY)
map_scatter_fig = px.scatter_mapbox(us_cities, lat=”lat”, lon=”lon”, color=”State”, size=”Population”)
map_scatter_fig.show()