smith
smith

Reputation: 113

Is there a way to change origin axis (zeroline) on scatter graph?

Is there a way to change axes on scatter graph? let's say move the axis from (0,0) i.e (zero-line) to something like (3,3) and make a quadrant graph

I've tried setting the "zeroline" value on both "xaxis" and "yaxis" to False and then drawing two constant lines across both the axes from 'shapes'. But I'd want to know if there's any way to change the origin axes.

Here's the example in the image

import plotly.graph_objs as go
import plotly
import plotly.io as pio
trace0 = go.Scatter(
    x=[7],
    y=[7.5],
)
data = [trace0]
layout = {
    'xaxis': {
        'zeroline': False,
        'dtick': 1,
    },
    'yaxis': {
        'zeroline': False,
        'dtick': 1,

    },
    'shapes': [
        {
            'type': 'line',
            'x0': 5,
            'y0': 0,
            'x1': 5,
            'y1': 10,
            'line': {
                'width': 1,
            },
        },
        {
            'type': 'line',
            'x0': 0,
            'y0': 5,
            'x1': 10,
            'y1': 5,
            'line': {
                'width': 1
            },
        },
    ]
}
fig = {
    'data': data,
    'layout': layout,
}
plotly.offline.plot(fig)
pio.write_image(fig, 'images/test.png')

Upvotes: 4

Views: 5715

Answers (1)

vestland
vestland

Reputation: 61104

If you run help(fig['layout']['xaxis']) you'll see that the only options for zeroline are:

 zeroline
     Determines whether or not a line is drawn at along the
     0 value of this axis. If True, the zero line is drawn
     on top of the grid lines.
 zerolinecolor
     Sets the line color of the zero line.
 zerolinewidth
     Sets the width (in px) of the zero line.

So if your approach with...

setting the "zeroline" value on both "xaxis" and "yaxis" to False and then drawing two constant lines across both the axes from 'shapes'.

...works out for you, I really think that's your best option.

Upvotes: 3

Related Questions