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

流过昼夜 提交于 2021-01-27 11:15:32

问题


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')

回答1:


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.



来源:https://stackoverflow.com/questions/55897305/is-there-a-way-to-change-origin-axis-zeroline-on-scatter-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!