我正在寻找使用python绘图地调整y轴距离的解决方案。情节中的哪个参数可以帮助我执行它?
这是用于更改刻度值和刻度名称,但我不知道如何禁用y轴的自动边距并更改其距离。
import plotly.graph_objs as go
import pandas as pd
from plotly.offline import init_notebook_mode, iplot
from plotly.graph_objs import *
init_notebook_mode(connected=True)
这是示例数据
Time = {'trace1':[0.02123456,0.14564545,0.01456445,0.914564],
'trace2':[0.14564564,0.00245646,0.0045646,0.0345646],
'dd':['2019-09-09','2019-09-10','2019-09-11','2019-09-12']}
df = pd.DataFrame(Time,columns=['trace1','trace2','dd'])
创建跟踪1
trace1 = go.Scatter(x = df.dd,
y = df.trace1,
mode = "lines",
name = "trace1",
marker = dict(color = 'rgba(42, 140, 239, 1)')
)
创建跟踪2
trace2 = go.Scatter(x = df.dd,
y = df.trace2,
mode = "lines",
name = "trace2",
marker = dict(color = 'rgba(239, 140, 42, 1)'))
这是用于创建图形的代码
data = [trace1,trace2]
layout = go.Layout(
title = 'Estimated Time',
xaxis = go.layout.XAxis(
tickformat = '%Y-%m-%d',
tickangle = 45),
yaxis = go.layout.YAxis(range = [0.001,1],
autorange = False,
title = "Seconds",
tickvals = [0.0010,0.0100,0.1000,1.0000],
ticktext= ["0.0010","0.0100","0.1000","1.0000"]
),
legend = dict(orientation="h",x=0.4,y = -0.2)
)
fig = dict(data = data, layout = layout)
iplot(fig)
当前结果:
预期结果(无重叠)
答案 0 :(得分:0)
在这种特殊情况下,您似乎想对数标度,因此我建议将type='log'
添加到go.Layout.Yaxis()
的参数中。