03-31-2023 05:20 PM
I am running jupyter notebook on a Databricks cluster and attempting to render a map. I tried the example from the documentation to test and it doesn't plot the points.
# Load data from sample csv
data_url = 'https://raw.githubusercontent.com/mapbox/mapboxgl-jupyter/master/examples/data/points.csv'
df = pd.read_csv(data_url)
# Must be a public token, starting with `pk`
token = mapbox_token
# Create a geojson file export from a Pandas dataframe
df_to_geojson(df, filename='points.geojson',
properties=['Avg Medicare Payments', 'Avg Covered Charges', 'date'],
lat='lat', lon='lon', precision=3)
# Generate data breaks and color stops from colorBrewer
color_breaks = [0,10,100,1000,10000]
color_stops = create_color_stops(color_breaks, colors='YlGnBu')
# Create the viz from the dataframe
viz = CircleViz('points.geojson',
access_token=token,
height='400px',
color_property = "Avg Medicare Payments",
color_stops = color_stops,
center = (-95, 40),
zoom = 3,
below_layer = 'waterway-label'
)
viz.show()
04-02-2023 03:42 AM
Hi @Keval Shah, Your code seems fine and should plot the points on the map. However, if you are still facing issues, try the following troubleshooting steps:
!pip install mapboxgl pandas
import os
import pandas as pd
from mapboxgl.utils import create_color_stops, df_to_geojson
from mapboxgl.viz import CircleViz
mapbox_token = "YOUR_MAPBOX_ACCESS_TOKEN"
os.environ["MAPBOX_ACCESS_TOKEN"] = mapbox_token
# Load data from sample csv
data_url = 'https://raw.githubusercontent.com/mapbox/mapboxgl-jupyter/master/examples/data/points.csv'
df = pd.read_csv(data_url)
# Create a geojson file export from a Pandas dataframe
df_to_geojson(df, filename='points.geojson',
properties=['Avg Medicare Payments', 'Avg Covered Charges', 'date'],
lat='lat', lon='lon', precision=3)
# Generate data breaks and color stops from colorBrewer
color_breaks = [0, 10, 100, 1000, 10000]
color_stops = create_color_stops(color_breaks, colors='YlGnBu')
# Create the viz from the dataframe
viz = CircleViz('points.geojson',
access_token=mapbox_token,
height='400px',
color_property="Avg Medicare Payments",
color_stops=color_stops,
center=(-95, 40),
zoom=3,
below_layer='waterway-label')
viz.show()
04-02-2023 12:58 PM
Hi @Kaniz Fatma
Thanks for the response.
I have all the required libraries installed to render the map. The code that I linked is from the official mapbox docs. see here: https://github.com/mapbox/mapboxgl-jupyter.
It doesn't appear to be an issue with the token because the map is being rendered in the output cell.
The issue seems to be the data points in `points.geojson` do not appear on the map. That layer is missing. It doesn't throw any errors either, at least in the cell output. The only warning I see is:
/databricks/python/lib/python3.9/site-packages/IPython/core/display.py:419: UserWarning:
Consider using IPython.display.IFrame instead
I suspect if you attempt to reproduce on your end within jupyter running on databricks compute, you may experience the same issue.
For reference, I am using:
python 3.9
mapboxgl 0.10.2
04-04-2023 04:44 PM
@Kaniz Fatma Do you have any updates? were you able to reproduce the error? i am not able to plot within jupyter notebook.
Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections.
Click here to register and join today!
Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.