Treemap chart

Hi bokehers’

is there a rapid way to do a Treemap chart like
Treemap Charts | Python | Plotly ?
Or shall I need to code it :cold_face:

Hi @odadoun ,

There is not right now, no. If you decide to code it up, we’d love to see it. :slight_smile:

1 Like


Depending on your requirements, you might be able to leverage Holoviz panel to accomplish this with bokeh content as well.

In principle, you can combine bokeh models and figures, plotly, and other functionality in panel. And since the panel server is the bokeh server under the hood, you have all of that functionality too.

bokeh is my go-to visualization framework, but I often find that complementing it with some extras from panel works quite well.

Here’s a very simple example using one of the plotly examples in the link you provided, combined with a bokeh button that just acknowledges that it was pressed, i.e. no link between the button and the treemap.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import as px
import numpy as np

from bokeh.models import Button
import panel as pn


def press_cb():
    print("button press")

b = Button(button_type='primary', width=300, label='Press')

df ="year == 2007")
df["world"] = "world" # in order to have a single root node
fig = px.treemap(df, path=['world', 'continent', 'country'], values='pop',
                  color='lifeExp', hover_data=['iso_alpha'],
                  color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))

ui = pn.Column(b, fig)

@carolyn thanks but I think I will postponed this task :shushing_face:
@_jm thanks your solution seems to be very good :crazy_face:

1 Like