Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: How to set zeroline opacity?

Is there a way to change the opacity of the zeroline in plotly? I am trying to layer the zeroline for my y-axis over my plot so it does not appear behind, but also have opacity/alpha of 50%. Is this possible?

like image 738
Ferhat Avatar asked Feb 27 '26 19:02

Ferhat


1 Answers

You can use an rgba color together with fig.update_xaxes() and /or fig.update_yaxes()to get any color with any opacity you would like:

enter image description here

Complete code:

import plotly.express as px

fig = px.line(y=[1, -1], x=[-1,1])

fig.update_xaxes(zeroline=True, zerolinewidth=6, zerolinecolor='rgba(0,255,0,0.5)')
fig.update_yaxes(zeroline=True, zerolinewidth=6, zerolinecolor='rgba(0,0,255,0.5)')

fig.show()
like image 157
vestland Avatar answered Mar 02 '26 08:03

vestland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!