TransWikia.com

Bokeh plot - Give colors to groups in categorical variable in scatter plot

Data Science Asked by DanielBulgar on March 14, 2021

I’m trying to create a scatterplot with all dots marked with a specific color representing a certain neigbourhood (categorical variable is neighbourhoodgroup consisting of 5 neighbourhoods). However, my code got an empty output, so no error or something, it’s just blank.

This is the code

plot = figure(tools=[hover])
colormap = CategoricalColorMapper(factors=list(set(data.neighbourhood_group)))
plot.circle(x=data.latitude, y=data.longitude, color = {'field': 'label', 'transform': colormap})
hover = HoverTool(tooltips=[('x', '$x'), ('y', '$y')])
plot.add_tools(hover)
output_notebook()
output_file('bokeh.html')
show(plot)

This is the result I actually want (in seaborn):

sns.scatterplot(data.longitude, data.latitude, hue=data.neighbourhood_group)

Plot neighbourhoods

Hope someone can tell what I’m doing wrong…

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP