Can not set a range when the ax is reversed -plotly

Viewed 273

Following the answer given to me on my previous question, I could use Plotly to plot with a rotated axis.

However, I cannot resize the range of the axis:

I have

layout1= go.Layout(title=go.layout.Title(text="A graph",x=0.5),
        xaxis={'title':'y[m]','range':[-10,10]},
        yaxis={'title':'x[m]', 'side':'right'})

# switch the x- and y-coordinates
point_plot=[
            go.Scatter(y=[3],x=[1],name="V0"),
            go.Scatter(y=[5],x=[2],name="GT"),
            go.Scatter(y=[0],x=[0],name="egoCar")
    ]


fig = go.Figure(data=point_plot, layout=layout1)

# reverse the range of the xaxis (which contains the y values)
fig.update_xaxes(autorange="reversed")
fig.show()

As you can see I would like that the Y-axis (that is horizontal now) goes from -10 to 10 However, I get

enter image description here

so apparently the range is not working. I suppose it is because the "autorange" but I need this since the axe Y needs to be reversed.

How can I do that?

1 Answers

I found the answer. Apparently to reverse an axis you don't need to autorange it, but just set the range backwards

layout1= go.Layout(title=go.layout.Title(text="A graph",x=0.5),
#        xaxis={'title':'y[m]','autorange':'reversed','range':[-10,10]},
        xaxis={'title':'y[m]'},
        yaxis={'title':'x[m]', 'side':'right'})

# switch the x- and y-coordinates
point_plot=[
            go.Scatter(y=[3],x=[1],name="V0"),
            go.Scatter(y=[5],x=[2],name="GT"),
            go.Scatter(y=[0],x=[0],name="egoCar")
    ]


fig = go.Figure(data=point_plot, layout=layout1)

# reverse the range of the xaxis (which contains the y values)
#fig.update_xaxes(autorange="reversed")
fig.update_xaxes(range=[10,-10])  #BACKWARDS
fig.show()
Related