【问题标题】:Python Dash graph line label cutoffPython Dash 图线标签截止
【发布时间】:2020-06-25 17:36:52
【问题描述】:

我正在使用 Dash 制作布尔 Pandas 系列的折线图,标签为截止。

有人知道如何修复截止标签吗?

这是我的布局代码:

    layout = dict(
        margin=dict(l=25, r=25, b=40, t=40),
        hovermode="closest",
        legend=dict(font=dict(color='#7f7f7f'), orientation="h"),
        title=gateway_obj.location,
        font=dict(
            color="#7f7f7f"
        ),
    )

这是我的数据代码:

    data = []
    for col in cols_chosen:
        data.append({
            'x': df['timestamp_local'],
            'y': df[col],
            'name': col,
            'type': 'scatter',
            'mode': 'lines',
            'line': {
                'shape': 'spline', 
                'smoothing': .2
            }, 
        })

    figure = {
        'data': data, 
        'layout': layout
    }

这个图表也绘制了其他时间序列,但布尔值是唯一给我带来问题的。

其他可能相关的信息:

上面的代码为 Dash dcc.Graph() 对象创建了图形,该对象位于三个 Bootstrap HTML div(容器、行和列)中。 div没有什么特别之处。我尝试在 div 上添加填充和边距,它只是将图形推到右侧,而没有修复截止标签。

谢谢! 肖恩

【问题讨论】:

    标签: python python-3.x plotly-dash


    【解决方案1】:

    我真傻,我只需要在左侧布局的“边距”字典中添加更多边距:

    margin=dict(l=40, r=25, b=40, t=40),

    问题已解决...现在是完整布局:

    layout = dict(
        margin=dict(l=40, r=25, b=40, t=40),
        hovermode="closest",
        legend=dict(font=dict(color='#7f7f7f'), orientation="h"),
        title=gateway_obj.location,
        font=dict(
            color="#7f7f7f"
        ),
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      • 2021-10-25
      • 1970-01-01
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多