如何对与legendgroup类似的跟踪名称进行分组?

时间:2019-05-27 17:32:00

标签: hover trace plotly.js info

我创建了一个带有分组图例的填充图表。 图例中的两个是最小值-最大值,分别在“最小值”和“最大值”列中列出。 我还需要在hoverinfo中对这些值进行分组,从逻辑上讲,这将与Legendgroup相似,但是我似乎无法在任何地方找到答案,并且在搜索时,我在plotly自己的文档中仅看到非常简单的hoverinfo示例。 因此,例如对于x = 1960,y的最小值和最大值应在hoverinfo中列为最小值-最大值:-0.24--0.19

图表:

https://plot.ly/~marialaustsen/2/pip-install-plotly-upgrade/#/

import pandas as pd

gmst_data = pd.read_csv('datasets/gmst.csv')
gmst_data


Year    Observations    Min Max Hincast Spread  ProbYear    ProbMonth
0   1960    -0.125028   -0.240861   -0.193750   -0.218470   -0.206202   0.0 0.0
1   1961    -0.133225   -0.206640   -0.134963   -0.199956   -0.194245   0.0 0.0
2   1962    -0.197759   -0.241336   -0.126120   -0.162079   -0.139568   0.0 0.0
3   1963    -0.331219   -0.317699   -0.181005   -0.227539   -0.202399   0.0 0.0
4   1964    -0.373632   -0.430987   -0.275372   -0.301794   -0.279481   0.0 0.0
5   1965    -0.226318   -0.280676   -0.136730   -0.267406   -0.214237   0.0 0.0
6   1966    -0.255212   -0.247974   -0.169003   -0.236345   -0.185526   0.0 0.0
7   1967    -0.257971   -0.275319   -0.181620   -0.242314   -0.193000   0.0 0.0
8   1968    -0.081026   -0.140823   -0.084356   -0.114128   -0.085527   0.0 0.0
9   1969    -0.173978   -0.251267   -0.114922   -0.205240   -0.184157   0.0 0.0
10  1970    -0.281273   -0.282577   -0.148437   -0.266685   -0.253780   0.0 0.0



trace1 = go.Scatter(
x = gmst_data['Year'],
y = gmst_data['Min'],
name = '',
legendgroup = 'minmax',    
fill='tonextx',
fillcolor = 'rgba(255, 255, 255, 0.0)',
mode= 'none',   
showlegend = False 
)

trace2 = go.Scatter(
x = gmst_data['Year'],
y = gmst_data['Max'],
name = 'Min - Max',
legendgroup = 'minmax',     
fill='tonexty',
fillcolor = '#2b908f',
mode= 'none' 

)

trace0 = go.Scatter(
x = gmst_data['Year'],
y = gmst_data['Observations'],
name = 'Observations',
mode = 'markers',
line = dict(
      color = '#79ea61'
    )  

)

trace3 = go.Scatter(
x = gmst_data['Year'],
y = gmst_data['Hincast'],
name = '',
legendgroup = 'hincastspread',
fill='tonextx',
fillcolor = 'rgba(255, 255, 255, 0.0)',
mode = 'none',
showlegend = False      

)

trace4 = go.Scatter(
x = gmst_data['Year'],
y = gmst_data['Spread'],
name = 'Hincast - Spread',
legendgroup = 'hincastspread',     
fill='tonexty',
fillcolor = '#F09448',
mode = 'none'    

)

data = [trace0, trace1, trace2, trace3, trace4]
layout = dict(title = 'Global mean surface Temperature',
              xaxis = dict(title = 'Year'),
              yaxis = dict(title = 'Temperature', hoverformat = '.2f'),
              )


fig = dict(data=data, layout=layout)

offline.iplot(fig)


0 个答案:

没有答案
相关问题