Plotly Y-axis "Zerolinecolor" not working?

Hi everyone,

I am playing with the design of my graph and I noticed that I cannot make the zero line for Y axis visible and change colour.
Interesting thing is that for X axis I do not have that issue.
I was hoping that zerolinecolor="white" line will show white zero line for both axis, but it’s not happening.
Screenshot and code below. Any ideas?
image

fig = px.bar(df_expenses, x="period", y="amount", template="plotly_dark", title="Expenses vs Salary")
    fig.add_trace(go.Scatter(x = df_salary["period"], y = df_salary["net"], name = "Net Salary"))
    fig.update_xaxes(
        title_text="Period",
        tickangle=-45,
        showgrid=False,
        zeroline=True,
        zerolinecolor="white"
    )
    fig.update_yaxes(
        title_text="Amount",
        tickprefix="zł",
        showgrid=False,
        zeroline=True,
        zerolinecolor="white"
    )

Hi @mrel,
You actually don’t need to pass zeroline=True and zerolinecolor="white" for x_axes. The zeroline originates from the zeroth value on the yaxis which you can see in white color overlapping the x-axis. To get a similar white color yaxis line add the below two properties to your update_yaxis function

 showline=True,
 linecolor="white"
fig = px.bar(
    x=["a", "b", "c"],
    y=[20, 10, 40],
    template="plotly_dark",
    title="Expenses vs Salary",
)
fig.add_trace(go.Scatter(x=["a", "b", "c"], y=[20, 10, 40], name="Net Salary"))
fig.update_xaxes(
    title_text="Period",
    tickangle=-45,
    showgrid=False,
)
fig.update_yaxes(
    title_text="Amount",
    tickprefix="zł",
    showgrid=False,
    zeroline=True,
    zerolinecolor="white",
    showline=True,
    linecolor="white"
)
fig.show()

It worked. Thank you, @atharvakatre .

What I noticed now is that Y and X have different width.
It’s visible on your screenshot and here is mine.
image

I tried adding zerolinewidth to X-axis but it isn’t working.

@mrel
The yaxis line width can be adjusted by using the linewidth property

fig.update_yaxes(
    title_text="Amount",
    tickprefix="zł",
    showgrid=False,
    zeroline=True,
    zerolinecolor="white",
    showline=True,
    linecolor="white",
    linewidth=2
)
1 Like

Works. Thank you very much!