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

2024-02-16

有没有办法改变散点图上的轴?假设将轴从 (0,0) 即(零线)移动到 (3,3) 之类的位置并制作象限图

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

这是图片中的示例 https://i.stack.imgur.com/VXcj6.png

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

如果你跑help(fig['layout']['xaxis'])你会发现唯一的选择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.

所以如果你的方法...

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

...适合你,我真的认为这是你最好的选择。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有没有办法改变散点图上的原点轴(零线)? 的相关文章

随机推荐