Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove axes and numbers from Plotly

Tags:

plot

plotly

I have the following picture, and I want to remove everything besides the dots and the triangle, which means the numbers on the horizontal and vertical axes and the small vertical lines, how can I do it?

Here is the picture:

Triangle

And here is my code:

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')
like image 579
Alfred Avatar asked Feb 22 '19 11:02

Alfred


People also ask

How do you remove axis labels in Plotly?

Toggling axis labels The axis tick mark labels can be disabled by setting the showticklabels axis property to False . Here is an example of disabling tick labels in all subplots for a faceted figure created using Plotly Express.

How do you hide xaxis in Plotly?

Solution. You need to use visible=False inside fig. update_yaxes() or fig.

How do you limit y axis in Plotly?

If I understand you right you want to limit the range of the y-axis itself. You can pass a dict in the keyword argument yaxis . It could be something like go. Layout(yaxis=dict(range=[0, 10])) I hope this helps you.

How do I delete a Plotly legend?

In this example, we are hiding legend in Plotly with the help of method fig. update(layout_showlegend=False), by passing the showlegend parameter as False.


2 Answers

To turn off the axes:

'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

also if you want to remove the legend:

layout = {
    'showlegend': False,
    ...
like image 110
vlizana Avatar answered Nov 10 '22 21:11

vlizana


To turn off axes in newer versions:

#legend
fig.update_layout(showlegend=False)

#x axis
fig.update_xaxes(visible=False)

#y axis    
fig.update_yaxes(visible=False)
like image 20
Ben Wilson Avatar answered Nov 10 '22 22:11

Ben Wilson