简体   繁体   English

如何在Python Plotly中创建具有共享x轴和范围滑块的子图

[英]How to create a subplot with shared x-axis and range slider in Python Plotly

I'm trying to create a specific plot with Python and Plotly. 我正在尝试用Python和Plotly创建一个特定的情节。 I was wondering if it's possible to create a plot with 3 subplots arranged vertically ( https://plot.ly/python/subplots/ ) that have a shared x-axis, along with a range slider that controls the x-axis ( https://plot.ly/python/range-slider/ )? 我想知道是否有可能创建一个带有3个垂直排列的子图( https://plot.ly/python/subplots/ )的图,它有一个共享的x轴,以及一个控制x轴的范围滑块( https ://plot.ly/python/range-slider/ )?

截至2017年1月,你不能这样做,请看这里: https//github.com/plotly/plotly.js/issues/1250

Today, Jan 24th 2017, I have managed to create stacked plots that share one x-axis, in combination with a range slider. 今天,2017年1月24日,我设法创建了共享一个x轴的堆积图,并结合了一个范围滑块。 However, the problem is that the range of the y-axis is automatically set. 但是,问题是y轴的范围是自动设定的。 I cannot control it. 我无法控制它。 This is a plroblem for me. 这对我来说是个问题。 My code is: 我的代码是:

trace_1 = go.Scatter(
    x=time_station1,
    y=turb_station1,
    mode = 'lines+markers',
    name = 'Turbidity',
    connectgaps = False,
    marker = dict(
        size = 5,
        color = 'rgb(64, 97, 139)',
        line = dict(
            width = 1,
            color = 'rgb(64, 97, 139)' 
        )
    )
)
trace_2 = go.Scatter(
    x=time_station1,
    y=battery_station1,
    yaxis='y2',
    mode = 'lines+markers',
    name = 'Battery',
    connectgaps = False,
    marker = dict(
        size = 5,
        color = 'rgb(117, 15, 7)',
        line = dict(
            width = 1,
            color = 'rgb(117, 15, 7)'
        )
    )
)
trace_3 = go.Scatter(
    x=time_station1,
    y=cond_station1,
    yaxis='y3',
    mode = 'lines+markers',
    name = 'Conductivity',
    connectgaps = False,
    marker = dict(
        size = 5,
        color = 'rgb(130, 0, 132)',
        line = dict(
            width = 1,
            color = 'rgb(130, 0, 132)'
        )
    )
)
trace_4 = go.Scatter(
    x=time_station1,
    y=depth_station1,
    yaxis='y4',
    mode = 'lines+markers',
    name = 'Depth',
    connectgaps = False,
    marker = dict(
        size = 5,
        color = 'rgb(204, 100, 0)',
        line = dict(
            width = 1,
            color = 'rgb(204, 100, 0)'
        )
    )
)
trace_5 = go.Scatter(
    x=time_station1,
    y=temp_station1,
    yaxis='y5',
    mode = 'lines+markers',
    name = 'Temperature',
    connectgaps = False,
    marker = dict(
        size = 5,
        color = 'rgb(255, 255, 0)',
        line = dict(
            width = 1,
            color = 'rgb(255, 255, 0)'
        )
    )
)

layout = go.Layout(
    title='Station ABC',
    xaxis = dict(
        rangeselector=dict(
            buttons = list([
                dict(count=1,
                     label='1min',
                     step='minute',
                     stepmode='backward'),
                dict(count=24,
                     label='24h',
                     step='hour',
                     stepmode='backward'),    
            ])
        ),
        rangeslider=dict(),
        type='date',
        title='Date and Time'
    ),
    yaxis=dict(
        domain=[0,0.15]),
    yaxis2=dict(
        domain=[0.2,0.35]),
    yaxis3=dict(
        domain=[0.4,0.55]),
    yaxis4=dict(
        domain=[0.4,0.75]),
    yaxis5=dict(
        domain=[0.8,1]),
        )

data = [trace_1, trace_2, trace_3, trace_4, trace_5]

plot_url = py.plot(fig, filename='offline plot.html')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 plotly.express 在顶部创建带有共享 x 轴的条形 plot? - How to create a bar plot with shared x-axis using plotly.express with sub-titles on top? Plotly:如何 plot 多条线与共享 x 轴? - Plotly: How to plot multiple lines with shared x-axis? 你如何获得 Plotly 图的 x 轴的范围? - How do you get the range of the x-axis of a Plotly graph? 如何在Python API中使用plotly在x轴范围中间位置绘制垂直线? - How to plot a vertical line at the x-axis range median position using plotly in Python API? 如何在 Plotly Python 中设置多索引 x 轴的范围? - How to set the range of multi-index x-axis in Plotly Python? 有没有办法用 plotly 或 python 创建条形图可视化,其中 y 轴是 24 小时范围,x 轴是所有工作日? - Is there a way to create a bar graph visualization with plotly or python where the y-axis is 24hour range and x-axis is all the weekdays? Plotly:当滑块用于显示连续直方图时,强制 x 轴范围保持不变 - Plotly: Force x-axis range to remain constant when slider is used to display sequential histograms 如何在 Python Plotly 中显示时间戳 x 轴 - How to show timestamp x-axis in Python Plotly python - 如何在python plotly express中对x轴标签和图例进行排序? - How to sort x-axis label and legends in python plotly express? 在 Plotly Python 中移动 x 轴和 y 轴刻度 - Moving the x-axis and y-axis ticks in Plotly Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM