cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

geojson file doesn't plot points on mapbox in jupyter notebook

kll
New Contributor III

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()

3 REPLIES 3

Kaniz
Community Manager
Community Manager

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:

  • Ensure the required libraries are installed:

!pip install mapboxgl pandas
  • Import necessary libraries:

import os
import pandas as pd
from mapboxgl.utils import create_color_stops, df_to_geojson
from mapboxgl.viz import CircleViz
  • Set your Mapbox access token:
mapbox_token = "YOUR_MAPBOX_ACCESS_TOKEN"
os.environ["MAPBOX_ACCESS_TOKEN"] = mapbox_token
  • Run the rest of your code as-is:
# 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()
  • If you still face issues, please provide more information about any errors or unexpected behaviour you encounter. This will help me better understand the problem and provide a more accurate solution.

kll
New Contributor III

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

kll
New Contributor III

@Kaniz Fatma​  Do you have any updates? were you able to reproduce the error? i am not able to plot within jupyter notebook.

Welcome to Databricks Community: Lets learn, network and celebrate together

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.