Plotly Treemap not working? - Python


So I’ve been attempting to generate a Treemap using the Plotly docs described here:

However, when I try to generate a basic plot I get the error:

import plotly.graph_objects as go

df = pd.read_csv('keyword-data.csv')

fig = go.Figure(go.Treemap(
    labels = df['Keyword'],
    parents = df['Topic']

AttributeError: module ‘plotly.graph_objects’ has no attribute ‘Treemap’

Has the Treemap plot been deprecated? Is there anyway to get it working?

It is a new trace type.
Are you using the latest version?

你好 你的这个问题解决了吗?

import as px
import pandas as pd
vendors = ["A", "B", "C", "D", None, "E", "F", "G", "H", None]
sectors = ["Tech", "Tech", "Finance", "Finance", "Other",
        "Tech", "Tech", "Finance", "Finance", "Other"]
regions = ["North", "North", "North", "North", "North",
        "South", "South", "South", "South", "South"]
sales = [1, 3, 2, 4, 1, 2, 2, 1, 4, 1]
df = pd.DataFrame(
    dict(vendors=vendors, sectors=sectors, regions=regions, sales=sales)
df["all"] = "all"  # in order to have a single root node

fig = px.treemap(df, path=['all', 'regions',
                        'sectors', 'vendors'], values='sales')

plotly 4.3.0 pypi_0 pypi
plotly-express 0.4.1 pypi_0 pypi

Hi @radial welcome to the forum! The path attribute of px.treemap was introduced in plotly 4.5, please upgrade your version of plotly. Also you can uninstall the plotly-express module since it is now part of plotly. Could you please write in English another time so that users can understand your posts? Thanks!


Thank you very much,I try it. And my Eiglish is not well. :sweat_smile:

According to your description, I ran successfully, thank you very much :grinning:

1 Like

Ok. I did not know that plotly-express was now part of plotly.

Is it possible to add an image to a treemap element ? There is a lot of space in those boxes. Ideally, I would like to place a word map in each box. Is there a way to do that ?

@user123 you may consider opening a feature request on plotly.js repo for displaying images in treemap nodes.

Hey Emmanuelle,
I am writing a notebook that will be shared across many people in Google Colab and the version there is not updated. I don’t want to force every user to install again and again. What can we use in order to make it work with an older version? (before path was introduced)
Your assistance will be greatly appreciated,