首页 > 解决方案 > Plotly - yaxis 最小值和最大值未显示

问题描述

我正在使用 plotly 创建一些情节。我没有修改 y 轴范围,但我不喜欢图表显示 y 轴的方式。在附加的图像中,图表 y 轴数从 25 到 40,但我的数据略高于 40 和低于 25。是否可以选择强制 y 轴始终高于我拥有的最小值和最大值? 另外,是否可以让 y 轴从边缘开始?(以紫色突出显示)

感谢您的时间!

在此处输入图像描述

编辑:正如评论中所要求的,我在下面添加了我的代码:

fig= go.Figure()

fig.update_layout(
        template="simple_white",
        font=_a_font,
        height=400,
        legend=dict(
            orientation="h",
            yanchor="bottom",
            y=1.02,
            xanchor="left",
            x=0,
            font=dict(size=16),
            itemclick=False,
            itemdoubleclick=False,
        ),
    )

fig.update_layout(xaxis=dict(range=x_range, mirror=True, tickmode='linear', tick0=0,dtick=1))
        
fig.update_yaxes(showgrid=True,mirror=True)
   
            
fig.add_trace(go.Scatter(x=sub_x_data,
                         y=y, 
                         mode="lines+markers", 
                         name=legend_name,
                         line=dict(color=get_driver_color(legend_name)),
                                         textposition="bottom center",
                                         text = h_data,
                                         hoverinfo="text"))

标签: plotlyplotly-python

解决方案


查看您的代码会很有帮助,因为此图表看起来不像 Plotly 中的默认样式图表。

话虽如此,您应该能够手动设置范围,并指定第一个刻度的位置:fig.update_yaxes(range=[20, 45], tick0=0)


推荐阅读