Python虚线图线标签截断

2024-05-08 13:56:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我用破折号画了一个布尔系列的折线图,标签是截断

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

graph with label cutoff

以下是我的布局代码:

    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()对象的图形,该对象位于三个引导HTML div(容器、行和列)中。这两个女主角没什么特别的。我尝试在div上添加填充和边距,它只是将图表向右推,而没有固定截止标签

谢谢! 肖恩


Tags: 对象代码divdfdata图表序列col
1条回答
网友
1楼 · 发布于 2024-05-08 13:56:08

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

保证金=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"
    ),
)

picture showing label fixed

相关问题 更多 >