developmentseed / lonboard

A Python library for fast, interactive geospatial vector data visualization in Jupyter.
https://developmentseed.org/lonboard/latest/
MIT License
639 stars 33 forks source link

Integrate `mapclassify` #136

Open kylebarron opened 1 year ago

kylebarron commented 1 year ago

From the geopandas.plot docstring

Name of a choropleth classification scheme (requires mapclassify). A mapclassify.MapClassifier object will be used under the hood. Supported are all schemes provided by mapclassify (e.g. ‘BoxPlot’, ‘EqualInterval’, ‘FisherJenks’, ‘FisherJenksSampled’, ‘HeadTailBreaks’, ‘JenksCaspall’, ‘JenksCaspallForced’, ‘JenksCaspallSampled’, ‘MaxP’, ‘MaximumBreaks’, ‘NaturalBreaks’, ‘Quantiles’, ‘Percentiles’, ‘StdMean’, ‘UserDefined’). Arguments can be passed in classification_kwds.

davidbailey commented 10 months ago

The following worked for me:



import numpy

from lonboard import Map, SolidPolygonLayer
from mapclassify import JenksCaspall

layer = SolidPolygonLayer.from_geopandas(zones_interpolated, opacity=0.2)
jc = JenksCaspall(
    zones_interpolated["ProductionAttractionSum Density"].fillna(0),
    k=20
)
colors = []
for color in jc.yb:
    colors.append(Viridis_20.colors[color])
layer.get_fill_color = numpy.uint8(colors)

Map(layers=[layer])
kylebarron commented 9 months ago

Thanks! By the way, I'm not sure where Viridis_20 comes from, but doing an array lookup would be much faster than a loop. You should probably be able to do something like

Viridis_20.colors[jc.yb]