首页 > 解决方案 > 如何从 Plotly 中删除轴和数字

问题描述

我有下面的图片,我想删除除了点和三角形之外的所有东西,这意味着水平和垂直轴上的数字以及小的垂直线,我该怎么做?

这是图片:

三角形

这是我的代码:

x0 = np.average(triangleEdges,axis=0,weights=np.array([0.2,0.1,0.7]))[0]
y0 = np.average(triangleEdges,axis=0,weights=np.array([0.2,0.1,0.7]))[1]

x1 = np.average(triangleEdges,axis=0,weights=np.array([0.5,0.1,0.7]))[0]
y1 = np.average(triangleEdges,axis=0,weights=np.array([0.5,0.1,0.7]))[1]


trace0 = go.Scatter(
    x=[x0],
    y=[y0],
    marker = dict(
        size = 15,
        color = 'rgba(25, 181, 254, 1)',
        line = dict(
            width = 1,
            color = 'rgb(0, 0, 0)'
        )
    )
)

trace1 = go.Scatter(
    x=[x1],
    y=[y1],
    marker = dict(
        size = 15,
        color = 'rgba(152, 0, 0, .8)',
        line = dict(
            width = 1,
            color = 'rgb(0, 0, 0)'
        )
    )
)


data = [trace0,trace1]
layout = {

'xaxis': { 

    'range': [0.2, 1],
    'zeroline': False,
    },
    'yaxis': {
        'range': [0, 1],
        'showgrid': False,
    },
    'shapes': [
       
       
        # filled Triangle
        {
            'type': 'path',
            'path': ' M 0.2 0 L 1 0 L 0.6 1 Z',
            'fillcolor': 'rgba(44, 160, 101, 0.5)',
            'line': {
                'color': 'rgb(44, 160, 101)',
            },
        },
       
    ]
}
fig = {
    'data': data,
    'layout': layout,
}

py.iplot(fig, filename='shapes-path')

标签: plotplotly

解决方案


要关闭轴:

'xaxis': {
    'range': [0.2, 1],
    'showgrid': False, # thin lines in the background
    'zeroline': False, # thick line at x=0
    'visible': False,  # numbers below
}, # the same for yaxis

如果你想删除图例:

layout = {
    'showlegend': False,
    ...

推荐阅读