说我有以下情节:
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
添加到xaxis
中的layout
参数中,但这似乎没有任何作用:
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'
,但它们也没有任何作用。
我该如何实现?
答案 0 :(得分:0)
您可以通过手动设置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)