本文介绍了如何从树状图的最外面的块中删除悬浮文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码使用plotly express创建了一个三级树形图:

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.

数据框如下所示:

        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

您能帮我从

推荐答案

添加 custom_data = [col1,col2等]
删除textinfo和hoverinfo的代码,使用

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}'

这篇关于如何从树状图的最外面的块中删除悬浮文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 15:58