有没有办法在散点图中更改原点坐标轴(零线)?

4

有没有办法在散点图上更改坐标轴?比如将坐标轴从(0,0)即(零线)移动到类似于(3,3)并制作象限图。

我尝试在“xaxis”和“yaxis”上设置“zeroline”值为False,然后从“shapes”绘制两条常数线穿过两个坐标轴。但我想知道是否有任何方法可以更改原点坐标轴。

这里是图片示例

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个回答

3
如果您运行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,然后从“shapes”中在两个轴上绘制两条常数线,那么我认为这是您最好的选项。


1
关于@vestland上面所描述的“两条常数线”的例子,您可以参考这个答案 - S3DEV

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接