[英]How can I move/shift the y-axis in plotly figures?
Say I have the following plot: 说我有以下情节:
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)
I want to increment the x-ticks by 1, but while doing that the y-axis also moves 1 unit to the right (ie, the x-axis starts at 2 now instead of 1): 我想将x点增加1,但同时y轴也会向右移动1个单位(即,x轴从2开始而不是从1开始):
figure1['data'][0]['x'] = (2,3,4)
iplot(figure1)
I want to retain the original axis layout (ie, I still want the x-axis to start at 1, and not at 2, even though I incremented the x-axis values). 我想保留原始的轴布局(即,即使我增加了x轴的值,我仍然希望x轴从1开始而不是从2开始)。 I tried adding
tickvals
and ticktext
to the xaxis
parameter in layout
, but that doesn't seem to have any effect: 我尝试将
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)
I also tried using tickmode='linear'
and ticks='outside'
, but they don't have any effect either. 我也尝试使用
tickmode='linear'
和ticks='outside'
,但它们也没有任何作用。
How can I achieve this? 我该如何实现?
You can accomplish this by manually setting the x axis range: 您可以通过手动设置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.