Plotly Dash - Gradient Lines

后端 未结 1 546
感动是毒
感动是毒 2021-01-21 12:33

Is it possible using Plotly Dash to create line graphs in which the line colors are gradient (purely for aesthetics) ?

I tried using something like

\'l         


        
1条回答
  •  失恋的感觉
    2021-01-21 13:03

    This feature is not yet available for 2D line plots, it is currently only available for 3D line plots, see https://github.com/plotly/plotly.js/issues/581. It is however possible to use a colorscale in a 2D plot if you use markers instead of lines, see the example below.

    import plotly.graph_objects as go
    import numpy as np
    
    t = np.linspace(0, 10, 1000)
    x, y = t, np.cos(t)
    
    data = go.Scatter(x=x, y=y, mode='markers', marker={'color': x, 'colorscale': 'Rainbow', 'size': 10})
    
    layout = dict(plot_bgcolor='white', margin=dict(t=0, b=0, r=0, l=0, pad=0),
                  xaxis=dict(showgrid=False, zeroline=False, mirror=True, linecolor='gray'),
                  yaxis=dict(showgrid=False, zeroline=False, mirror=True, linecolor='gray'))
    
    fig = go.Figure(data=data, layout=layout)
    
    fig.show()
    

    0 讨论(0)
提交回复
热议问题