Axis zerolines not starting at 0

Hi,

I have managed to create a scatter plot, however I would like the zerolines to cross at the value of 1 for both the X and Y axis, instead of the normal 0. I know there is a โ€˜baseโ€™ property for bar graphs, but is there an equivalent for scatter plots?

Hopefully the screenshot explains it more clearly - the way the graph is created means that 0 will never be displayed on either of the axisโ€™, so would like them to start at the value of 1.

Thanks!

Hi @ssj30, this is not possible with zerolines which have to go to zero, but you can emulate this behaviour using Shapes to draw vertical and horizontal lines. In particular, you can use the fact that you can define the x range of your line in data coordinates and the y range in paper coordinates in order to draw infinite lines. Please see the code below. However, it is quite non-standard to have crossing lines looking like axes but not going through zero and it might be misleading. May I recommend that you style these lines with a specific style which makes clear those are not the normal axes? The example shows how to do this, more examples are found on https://plot.ly/python/shapes/

import plotly.graph_objects as go
fig = go.Figure(go.Scatter(x=[1.5], y=[1.5]))
fig.add_shape(
        # Vertical Line
        go.layout.Shape(
            type="line",
            x0=1,
            y0=0,
            x1=1,
            y1=1,
            xref='x',
            yref='paper',
            line=dict(
                color="RoyalBlue",
                width=3
            )
))
fig.add_shape(
        # Vertical Line
        go.layout.Shape(
            type="line",
            x0=0,
            y0=1,
            x1=1,
            y1=1,
            xref='paper',
            yref='y',
            line=dict(
                color="RoyalBlue",
                width=3
            )
))
fig.show()
1 Like