【问题标题】:python plotly subplots - set domain for tablepython plotly subplots - 为表设置域
【发布时间】:2022-02-02 20:44:58
【问题描述】:

我试图找出如何在 plotly (V4.14.3) 的 2x2 子图中为表设置域。

我认为go.Table(domain=dict(x=[a,b],y=[c,d)) 中的“域”选项是正确的选项,但在更改值时不会移动。

我的目标是为上排的绘图设置一个固定的域,在下排设置一个动态表格和图例,因此如果我可以使用域选项改变表格位置,那将很容易。

如您所见,我将代码中的域设置为domain=dict(x=[0.0, 1.0],y=[0.2, 0.8]),这与您在附图中看到的结果不同。

非常感谢您

import plotly.graph_objs as go
from plotly.subplots import make_subplots

# Testdata
Test_DataSets = ['Set1','Set2','Set3']
Test_DataVals = [2,3,4]

x = [1,2,3,4,5]
y = [2,5,7,9,6]


# Plots
fig = make_subplots(
    rows=2, cols=2,
    specs=[[{"type": "scatter"},{"type": "scatter"}],
           [{"type": "table"},{"type": "scatter"}]
          ]
)

fig.add_trace(go.Scatter(x=x,y=y,
                         name= 'Testdata',
                         legendgroup = 'group'),1,1)

fig.add_trace(go.Scatter(x=x,y=y,
                         name= 'Testdata',
                         legendgroup = 'group'),1,2)

fig.add_trace(
    go.Table(domain=dict(x=[0.0, 1.0],y=[0.2, 0.8]),
             header=dict(
                 values=["DataSet", "Val"],
                 font=dict(size=10),
                 align="left"),
             cells=dict(
                 values=[Test_DataSets,Test_DataVals]
             )),
    row=2, col=1
)

fig.show()

this the result thats how it should be

【问题讨论】:

    标签: python dns plotly


    【解决方案1】:

    我自己找到了解决办法……

    可以使用以下代码设置域:

        fig.update_traces(domain_x=[0,0.45], domain_y=[0,0.45], selector=dict(type='table'))
    

    【讨论】:

      猜你喜欢
      • 2022-10-17
      • 2023-02-14
      • 2022-01-22
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 2019-03-31
      相关资源
      最近更新 更多