2

I have created a 3 level treemap using plotly express using below code:

    import plotly.express as px

    fig = px.treemap(veh_3d_data, path=['Date', 'Capacity.2', 'Transporter'], values='Vehicle Plate', 
             color='Capacity.2',
             #textinfo="label+value",
             labels = {'Date':'Date', 'Capacity.2':'Capacity', 'Transporter':'Transporter', 'Vehicle 
                       plate':'Vehicle Count' },
                            
             color_discrete_map={'(?)':'lightgray','18K':'tomato', '27K':'cadetblue', 
                                '36K':'darksalmon', '50K':'mediumseagreen', '45k':'lightsteelblue'}
             )

    fig.data[0].textinfo = 'label+value'
    fig.data[0].hoverinfo = 'skip'


    pyo.plot(fig, filename='veh_avail_tree.html')

but i am getting the hover text for the outermost block of the tree also as shown in the image attached.enter image description here

the data frame looks like this:

        Date    Capacity.2  Transporter Vehicle Plate
    0   2020-01-06  18K T4307423    4
    1   2020-01-06  18K T4308711    1
    2   2020-01-06  18K T4308874    3
    3   2020-01-06  27K T4300185    1
    4   2020-01-06  27K T4300330    1
    ... ... ... ... ...
    254 2020-01-18  36K T4311081    1
    255 2020-01-18  36K T4311504    1
    256 2020-01-18  50K T4306615    1
    257 2020-01-18  50K T4311082    2
    258 2020-01-18  50K T4311085    4

could you help me in removing the hovertext from the outer most block only?

1 Answers1

0

Add custom_data = [col1, col2, etc.] inside the px.treemap. Delete the codes for textinfo and hoverinfo, use

fig.data[0].hovertemplate='<b></b>%{label}'+ '<br> custom_column_name1: %{customdata[0]}'+'<br> custom_column_name2: %{parent}'+ '<br>custom_column_name3: %{value}'
Jiamei
  • 405
  • 3
  • 14