Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example displays base map but not points #182

Open
ryan-williams opened this issue Feb 5, 2021 · 2 comments
Open

Example displays base map but not points #182

ryan-williams opened this issue Feb 5, 2021 · 2 comments

Comments

@ryan-williams
Copy link

mapboxgl 0.10.2 in a Python 3.8.6 kernel in Jupyter:

Code
with open('mapbox_token.txt','r') as f:
    # Must be a public token, starting with `pk`
    token = f.read().strip()

import os

import pandas as pd

from mapboxgl.utils import create_color_stops, df_to_geojson
from mapboxgl.viz import CircleViz


# 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=token,
                height='400px',
                color_property = "Avg Medicare Payments",
                color_stops = color_stops,
                center = (-95, 40),
                zoom = 3,
                below_layer = 'waterway-label'
              )
viz.show()

mapboxgl jupyter widget showing base map but no points

I expected to see points on the map, like in the screenshot in the docs:
jupyter screenshot from docs showing points on a map

df looks vaguely reasonable / non-empty:
jupyter widget showing geojson dataframe

Also note the UserWarning mentioned in #150 (comment), not sure if it's relevant:

/usr/local/lib/python3.8/site-packages/IPython/core/display.py:717: UserWarning: Consider using IPython.display.IFrame instead
  warnings.warn("Consider using IPython.display.IFrame instead")

What am I missing? Thanks.

@ryan-williams
Copy link
Author

examples/notebooks/circle-vector.ipynb is basically the same viz, but constructed differently (it doesn't use df_to_geojson), and it works for me… not sure what the issue is with the df_to_geojson example

@korompaiistvan
Copy link

the problem is that it tries to parse 'points1.geojson' as a geojson string itself. you have to save the output of df_to_geojson to a variable and pass that to CircleViz instead. the main example is simply not correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants