Plotly legend title

前端 未结 4 682
既然无缘
既然无缘 2021-01-07 18:02

I\'d like to be able to add a title to the legend, in the following code. However, looking at the docs, I don\'t think there is a method for this.

import plo         


        
4条回答
  •  感情败类
    2021-01-07 19:04

    I've done this before by making a data-less trace

    import plotly.plotly as py
    import plotly.graph_objs as go
    
    dummy_trace = go.Scatter(
        x=[None], y=[None],
        name='Legend Heading',
        # set opacity = 0
        line={'color': 'rgba(0, 0, 0, 0)'}
    )
    
    trace0 = go.Scatter(
        x=[1, 2, 3, 4, 5],
        y=[1, 2, 3, 4, 5],
    )
    
    trace1 = go.Scatter(
        x=[1, 2, 3, 4, 5],
        y=[5, 4, 3, 2, 1],
    )
    
    data = [dummy_trace, trace0, trace1]
    fig = go.Figure(data=data)
    
    py.iplot(fig)
    

提交回复
热议问题