370
Chapter 17
'color': 'rgb(60, 100, 150)',
'line': {'width': 1.5, 'color': 'rgb(25, 25, 25)'}
},
'opacity': 0.6,
}]
--
snip--
We
first define a new empty list,
labels
, to hold the text we want to
display for each project u. In the
loop where we process the data, we pull
the owner and the description for each project v.
Plotly allows you to use
HTML code within text elements, so we generate
a string for the label with
a line break (
) between the project owner’s username and the descrip-
tion w. We then store
this label in the list
labels
.
In the
data
dictionary, we add an entry with the key
'hovertext'
and assign
it the list we just created x.
As Plotly creates each bar, it will pull labels from
this list and only display them when the viewer hovers over a bar.
Figure 17-3 shows the resulting chart.
Figure 17-3: Hovering over a bar shows the project’s owner and description.
Do'stlaringiz bilan baham: