有没有办法更改散点图上的原点轴(零线)?

时间:2019-04-29 05:14:55

标签: python plotly plotly-python

是否可以更改散点图上的轴?假设将轴从(0,0)(即零线)移动到类似(3,3)的位置,然后制作一个象限图

我尝试将“ xaxis”和“ yaxis”上的“ zeroline”值都设置为False,然后从“ shapes”沿两个轴绘制两条恒定线。 但是我想知道是否可以更改原点轴。

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 个答案:

答案 0 :(得分:0)

如果运行help(fig['layout']['xaxis']),则会看到zeroline的唯一选项是:

 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.

因此,如果您采用的方法是...

  

将“ xaxis”和“ yaxis”上的“ zeroline”值都设置为False和   然后从“形状”沿两个轴绘制两条恒定线。

...为您效劳,我真的认为这是您最好的选择。

相关问题