Michał Kowalski
Michał Kowalski

Reputation: 55

Scatter pie chart on map in Plotly or Bokeh in Python

Is there a possibility to create a scatter plot on a map within Plotly or Bokeh to make every single scatter point a mini pie chart? I can't find info in docs of plotly.graph_objects.Scattermapbox and bokeh.plotting.

Upvotes: 2

Views: 1035

Answers (1)

Michał Kowalski
Michał Kowalski

Reputation: 55

So, Bokeh in version 2.3.0 has been the solution (old versions will probably work too). You can find working example on sarswpolsce.pl Usage of p.wedge presented in this use-case is life-saving.

Here is pseudocode for desired effect:


    p = figure(x_range=(mercator_x_min, mercator_x_max),
               y_range=(mercator_y_min, mercator_y_max),
               x_axis_type="mercator", y_axis_type="mercator",
               tools=TOOLS, output_backend="webgl", #for faster rendering
               plot_width = plot_w, plot_height = plot_h,
               title = "title")
    
    p.add_tile(tile_provider)
    
    for w in coordinates.keys():
        lat, lon = converter(coordinates[w][0], coordinates[w][1])
        renderdict[w] = p.wedge(x=lon, y=lat, radius=radius_, alpha = alpha_,
                                start_angle=cumsum(f'Angle_{w}', include_zero=True),
                                end_angle=cumsum(f'Angle_{w}'),
                                line_color="white", fill_color=f'Color_{w}',
                                legend_field= legend,
                                source=data_source, name = w)

Upvotes: 2

Related Questions