Show Sidebar Hide Sidebar

Hover Events in Pandas

How to add custom hover effects to Pandas charts with JavaScript.

Note: this page is part of the documentation for version 3 of Plotly.py, which is not the most recent version.
See our Version 4 Migration Guide for information about how to upgrade.
import plotly.plotly as py
import plotly.graph_objs as go

data = [
    go.Bar(
        x=['Bob Dylan', 'The Beatles', 'David Bowie', 'Randy Newman', 'The Rolling Stones', 'Madonna', 'Frank Sinatra', 'The Beach Boys', 'Marvin Gaye', 'Prince', 'The Kinks', 'Elvis Presley', 'Tom Waits', 'U2', 'The Clash', 'Johnny Cash', 'Kate Bush', 'The Supremes', 'The Smiths', 'Al Green', 'Pulp', 'Chuck Berry', 'Elvis Costello and the Attractions', 'Neil Young', 'Stevie Wonder', 'Ray Charles', 'The Pogues', 'Grace Jones', 'Bill Withers', 'The Who', 'Paul Simon', 'Roy Orbison', 'Arctic Monkeys', 'Bruce Springsteen', 'The Police', 'Rod Stewart', 'Steve Earle'],
        y=[24, 19, 9, 8, 8, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        name='Number of songs per artist',
        marker=dict(color='#2ca02c')
    )
]
layout = go.Layout(
    title="Number of songs listed in the Guardian's<br><em>Top 1,000 Songs to Hear Before You Die</em> per artist with 4 or more songs",
    font=dict(
        family='Georgia, serif',
        color='#635F5D'
    ),
    showlegend=False,
    autosize=False,
    width=700,
    height=500,
    xaxis=dict(
        title='',
        ticks='outside',
        ticklen=8,
        tickwidth=1.5,
        tickangle=45
    ),
    yaxis=dict(
        title='Number of songs per artist',
        ticks='outside',
        ticklen=8,
        tickwidth=1.5,
        gridcolor='#FFFFFF'
    ),
    margin=dict(
        b=140
    ),
    plot_bgcolor='#EFECEA'
)
fig = go.Figure(data=data, layout=layout)
plot_url = py.plot(fig)