0

我正在寻找解决方案来使用 python 调整 y 轴的距离。plotly 中的哪个参数可以帮助我执行它?

这是为了更改刻度值和刻度名称,但我不知道如何禁用 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)

当前结果:

在此处输入图像描述

预期结果(无重叠):

在此处输入图像描述

4

1 回答 1

1

在这种特殊情况下,您似乎想要制作对数刻度,因此我建议添加type='log'go.Layout.Yaxis().

于 2019-07-17T18:23:56.060 回答