简体   繁体   English

具有多个标题或合并列的表Plotly Python

[英]Table with multiple headers or merged columns Plotly Python

我正在尝试使用回调函数在表中构建表,我正在使用Go.Table但无法创建多个标题

If I was correct read docs , you can not create multiple headers. 如果我没看错文档 ,则无法创建多个标题。

First possible solution is to move headers to values: 第一种可能的解决方案是将标头移至值:

import plotly
import plotly.graph_objs as go

trace = go.Table(
    header=dict(values=['Version', 'Baseline', 'Promo', 'VDP+']),
    cells=dict(values=[['', '08/20 to 08/27','08/13 to 08/20', '08/06 to 08/13',\
                        '07/30 to 08/06'],
                       ['Current Month: Aug 18', '', '', '', ''],
                       ['Current Month: Aug 18', '', '', '', ''],
                       ['Current Month: Aug 18', '', '', '', '']]))

data = [trace] 
plotly.offline.plot(data, filename = 'basic_table.html')

Looks like: 看起来像:

第一个解决方案

But you can not operate with them such as columns what is not great. 但是您不能对它们(例如列)进行操作,效果不是很好。

Second possible solution is to specify prefix (or suffix - depends what would you like more): 第二种可能的解决方案是指定prefix (或suffix -取决于您想要什么):

import plotly
import plotly.graph_objs as go

trace = go.Table(
    header=dict(values=['Version', '.Baseline', '.Promo', '.VDP+'], 
                prefix = ['','Current_Month:_Aug_18', 'Current_Month:_Aug_18',\
                          'Current_Month:_Aug_18'],
                ),
    cells=dict(values=[['08/20 to 08/27', '08/13 to 08/20', '08/06 to 08/13', \
                        '07/30 to 08/06'],
                       ['', '', '', ''],
                       ['', '', '', ''],
                       ['', '', '', '']]))

data = [trace] 
plotly.offline.plot(data, filename = 'basic_table.html')

And in this case, you can add your columns as prefix or suffix. 在这种情况下,您可以将列添加为前缀或后缀。

Looks like: 看起来像: 第二种解决方案

Update: Yep, you can create an empty row (just do not specify headers ): 更新:是的,您可以创建一个空行(只是不指定headers ): 空行

Update: Currently I found the way to get what you need: 更新:目前,我已经找到了满足您需求的方法:

import plotly
import plotly.graph_objs as go

trace = go.Table(
    header=dict(values=[['Version', ''],
                        ['Baseline', 'Current Month: Aug 18'],
                        ['Promo', 'Current Month: Aug 18'],
                        ['VDP+', 'Current Month: Aug 18']]),
    cells=dict(values=[['08/20 to 08/27', '08/13 to 08/20', '08/06 to 08/13', \
                        '07/30 to 08/06'],
                       ['', '', '', ''],
                       ['', '', '', ''],
                       ['', '', '', '']]))

data = [trace] 
plotly.offline.plot(data, filename = 'basic_table.html')

Looks like: 看起来像: 这就是您想要的,不是吗?

I can not hide one line but the whole lines of headers(add line = dict(width=0) after headers values): 我无法隐藏一行,而是隐藏标题的整行(在标题值后添加line = dict(width=0) ): 嗯 Or set the color of lines but for all the lines again (with same results as above) 或设置线条的颜色 ,但再次为所有线条设置(与上述结果相同)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM