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

Legend in Graduated Circle Viz only works when both color_property and radius_property specified #150

Closed
Geo-C-Data opened this issue Mar 19, 2019 · 13 comments

Comments

@Geo-C-Data
Copy link

I want to make a GraduatedCircleViz where the circles are sized by a column in a Pandas DataFrame. I don't have a secondary feature for which I'd like to vary the color.

If I only specify radius_propery, the visualization is correct, but the Legend is not shown (works fine when a secondary color feature is specified)

@akacarlyann
Copy link
Collaborator

@caerus-data Can you provide example code? Using the examples in examples/notebooks/legend-controls.ipynb, I was unable to recreate your issue. I'd like to help out -- I definitely hope to expand the customization on the map legends going forward :)

Here's what I tried just now:

import pandas as pd
import os
from mapboxgl.utils import *
from mapboxgl.viz import *

# Set Mapbox Acces Token; Must be a public token, starting with `pk`
token = os.getenv('MAPBOX_ACCESS_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).round(3)

# Generate radius breaks from data domain and circle-radius range
measure_radius = 'Avg Medicare Payments'
radius_breaks = [round(df[measure_radius].quantile(q=x*0.1), 2) for x in range(2,10)]
radius_stops = create_radius_stops(radius_breaks, 0.5, 10)

# Create the viz
viz2 = GraduatedCircleViz('../data/healthcare_points.geojson', 
                          access_token=token,
                          # color_property='Avg Covered Charges',
                          # color_stops=color_stops,
                          radius_property='Avg Medicare Payments',
                          radius_stops=radius_stops,
                          stroke_color='black',
                          stroke_width=0.5,
                          center=(-95, 40),
                          zoom=2.5,
                          opacity=0.75,
                          below_layer='waterway-label',
                          height='300px')
viz2.show()

This yielded a map with only the variable radius legend, which seems like what you are looking for. I'm on the master branch (after the maintainer merged in #135 earlier today). Since #135 included some changes to CSS and JS in the project, maybe if you clear your browser cache you'll have better luck?
variable_radius

@Geo-C-Data
Copy link
Author

Geo-C-Data commented Mar 20, 2019

import pandas as pd
import os
from mapboxgl.utils import *
from mapboxgl.viz import *

# Set Mapbox Acces Token; Must be a public token, starting with `pk`
token = os.getenv('MAPBOX_ACCESS_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).round(3)

# Generate radius breaks from data domain and circle-radius range
measure_radius = 'Avg Medicare Payments'
radius_breaks = [round(df[measure_radius].quantile(q=x*0.1), 2) for x in range(2,10)]
radius_stops = create_radius_stops(radius_breaks, 0.5, 10)

data=df_to_geojson(df
              #, filename='K22W.geojson'
              , lat='lat'
              , lon='lon'
              , precision=5)

# Create the viz
viz2 = GraduatedCircleViz(data, 
                          access_token=token,
                          # color_property='Avg Covered Charges',
                          # color_stops=color_stops,
                          radius_property='Avg Medicare Payments',
                          radius_stops=radius_stops,
                          stroke_color='black',
                          stroke_width=0.5,
                          center=(-95, 40),
                          zoom=2.5,
                          opacity=0.75,
                          below_layer='waterway-label',
                          height='300px')
viz2.show()

@Geo-C-Data
Copy link
Author

image

@Geo-C-Data
Copy link
Author

Sorry for the multiple comments - as you can see, I've duplicated the selected code with a minor change for geojson, and no legend displays.

I've deleted my browser (Chome, latest build) cache through the settings menu, but no effect.

Thanks so much for a wonderful toolbox and so much help!

@akacarlyann
Copy link
Collaborator

@caerus-data No problem! Thanks for sharing the snippet above. Since it looks like we are running essentially the same thing with different results, can you confirm the latest commit you have checked out? I do work on a different OS so I want to rule everything else out before tackling dev-environment differences.

@Geo-C-Data
Copy link
Author

Sure thing! I think this is what you're asking...

import mapboxgl
mapboxgl.__version__

'0.10.1'

@Geo-C-Data
Copy link
Author

Sorry if this wasn't clear, I'm on Windows 10.

@akacarlyann
Copy link
Collaborator

What method did you use for installing the package? Did you clone the repository using git? And if so, have you updated the master branch after the recent PR was merged?

I'm also starting to think this may be a bug in JavaScript. Can you access the JS console using the browser developer tools and let me know if there are any error messages there? Thanks!

@Geo-C-Data
Copy link
Author

pip install mapboxgl

Working on JS now

@Geo-C-Data
Copy link
Author

Geo-C-Data commented Mar 21, 2019

No Errors. I've been getting this warning within Jupyter though, which I've mentioned in other chains but not here. Sorry for not bringing it up sooner

C:\Users\MYUSERNAME\AppData\Local\Continuum\anaconda2\envs\geo36\lib\site-packages\IPython\core\display.py:689: UserWarning: Consider using IPython.display.IFrame instead
warnings.warn("Consider using IPython.display.IFrame instead")

@Geo-C-Data
Copy link
Author

My Anaconda is 2.7, but the environment is Python 3.6. I have this same problem in a 2.7 environment though.

@akacarlyann
Copy link
Collaborator

How about if you try pip install git+https://github.com/mapbox/mapboxgl-jupyter.git to install the latest development version?

@Geo-C-Data
Copy link
Author

Latest GitHub version resolved the issue! Thanks!

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