![](/img/trans.png)
[英]Dash/Plotly: How can I plot two columns on the y-axis with the same x axis?
[英]How can I move/shift the y-axis in plotly figures?
說我有以下情節:
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
trace1 = go.Scatter(x=[1,2,3], y=[4,5,6], marker={'color': 'red', 'symbol': 104, 'size': 10},
mode="markers+lines", text=["one","two","three"], name='1st Trace')
data=go.Data([trace1])
layout=go.Layout(xaxis={'title':'x1', 'showline':True}, yaxis={'title':'y1', 'showline':True}, height=380, width=380)
figure1=go.Figure(data=data,layout=layout)
init_notebook_mode(connected=True)
iplot(figure1, show_link=False)
我想將x點增加1,但同時y軸也會向右移動1個單位(即,x軸從2開始而不是從1開始):
figure1['data'][0]['x'] = (2,3,4)
iplot(figure1)
我想保留原始的軸布局(即,即使我增加了x軸的值,我仍然希望x軸從1開始而不是從2開始)。 我嘗試將tickvals
和ticktext
添加到layout
的xaxis
參數中,但這似乎沒有任何效果:
figure1['layout'] = {'xaxis':{'title':'x2',
'tickvals':[0,1,2,3,4,5],
'ticktext':[0,1,2,3,4,5],
'showline':True
},
'yaxis':{'title':'y1', 'showline':True},
'height':380,
'width':380
}
iplot(figure1)
我也嘗試使用tickmode='linear'
和ticks='outside'
,但它們也沒有任何作用。
我該如何實現?
您可以通過手動設置x軸范圍來完成此操作:
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
trace1 = go.Scatter(x=[1,2,3], y=[4,5,6],
marker={'color': 'red', 'symbol': 104, 'size': 10},
mode="markers+lines",
text=["one","two","three"],
name='1st Trace')
data = go.Data([trace1])
layout = go.Layout(xaxis = {'range': [0.75,4.25],
'title':'x1',
'showline':True},
yaxis = {'title':'y1',
'showline':True},
height=380, width=380)
figure1 = go.Figure(data=data, layout=layout)
figure1['data'][0]['x'] = (2,3,4)
plot(figure1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.