Python Dash Plotly: Show default closest data on hover or compare data on hover in graph

Setting your graph default to showing closest data in plotly dash can be done by adding hovermode to the figure, as follows:

figure={
    'data': [
        {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
        {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
    ],
    'layout': {
        'hovermode': 'closest',
    }
}

Setting your graph default to compare data is done by:

'layout': {
    'hovermode': 'compare',
}

Update to Sander van den Oord's answer, at least as of dash 1.0.2:

layout.hovermode = 'closest' # for "Show closest data on hover"
layout.hovermode = 'x' # for "Compare data on hover"

Other options include:

layout.hovermode = 'y' # similar to x but switches tags accordingly
layout.hovermode = False # nothing shown on hover