'How do a heatmap or lines of levels (on a map) with Bokeh?

I find a lot of example heatmap with Bokeh but it is with three variables (three values, for example: x, y and temperature). And it's not for a map. I would like to code lines of levels (distribution) of circles (not with a third value) on my map.

I know it is possible with other libraries but I build a Bokeh application, and I do not see how it is possible.

To start, I'm looking for a little example (with Bokeh) just on a graph with a few points.

To go from that :


(source: pydata.org)

To that :

with Bokeh (without the curves) with a legend maybe.

Thank a lot.

PS : I know this example, but it does not help for my needs.



Solution 1:[1]

As of Bokeh 1.0.2 this is possible, but not easily possible. Bokeh has recently added support for a newmulti_polygons glyph that affords "patches with holes".

p.multi_polygons(
    xs=[

        # first multi-polygon (blue)
        [[ [1, 1, 2, 2],
           [1.2, 1.6, 1.6],
           [1.8, 1.8, 1.6]], # sub-polygon with 2 holes

         [ [3, 3, 4] ], # sub-polygon with no holes

        # second multi-polygon (red)
        [[ [1, 2, 2, 1],
           [1.3, 1.3, 1.7, 1.7] ]], # sub-polygon with 1 hole
    ],
    ys=[
        [[ [4, 3, 3, 4], [3.2, 3.2, 3.6], [3.4, 3.8, 3.8] ], [ [1, 3, 1] ]],
        [[ [1, 1, 2, 2], [1.3, 1.7, 1.7, 1.3] ]]],
    color=['navy', 'crimson'])

enter image description here

This is a necessary pre-condition for being able to render contour plots such as the one you show above. However, Bokeh does not have any built-in functionality for computing the iso-contour levels, so you would have to generate those somehow, either using the numerical output of some other contouring function (e.g. maybe MPL or Seaborn will give you the raw contour data), or by computing them yourself.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bigreddot