Plotly: How to plot multiple lines with shared x-axis?

后端 未结 2 1176
温柔的废话
温柔的废话 2020-12-18 12:28

I would like to have a multiple line plot within same canvas tied with the same x-axis as shown something in the figure:

Using subplots does not achieve the i

2条回答
  •  离开以前
    2020-12-18 12:57

    Depending on the data you are plotting, I think you could either check out "Stacked Subplots with a Shared X-Axis (low-level API)" on https://plotly.com/python/subplots/

    Or separate the data by shifting each line plot upwards like so:

    import plotly.graph_objects as go
    import random
    
    
    data = []
    n = 9
    
    for x in range(10, 60, 10):
    
      points = [value + x for value in random.sample(range(1,n+1), k = n)]
      
      data.append(go.Scatter(y=points))
    
    fig = go.Figure(data = data)
    
    fig.show()
    

提交回复
热议问题