2 回答

TA貢獻1812條經驗 獲得超5個贊
我不知道 Plotly 有任何內置方法來切換 x 軸和 y 軸。但是,您可以自己實現這一點,但要切換 x 軸和 y 軸的標題,然后切換x與y您的點相對應的參數。
然后,您可以將 y 軸(包含您的 x 坐標)放在布局的右側,并反轉 x 軸(包含您的 y 坐標)的范圍,使原點位于右下方.
import plotly.graph_objects as go
# switch the axes titles
layout1= go.Layout(title=go.layout.Title(text="A graph",x=0.5),
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.show()

TA貢獻1824條經驗 獲得超8個贊
Derek O 找到了最容易實現的方法。這是1km的圖形類比是0.6英里或a, b = b, a
第二種選擇是抽象數據和軸。這本質上說的是同一件事,但可以更容易閱讀,因為 Plotly 具有獨特的能力,可以將清晰、結構良好的 Python 快速轉換為丑陋的 JS,無需括號。
選項三是進一步抽象它并讓它為你設置軸。
添加回答
舉報