Customizing the hover-over tooltip

By default, when hovering over a marker in an interactive figure, a tooltip will be shown with the time and y value for the markers:

The behavior of this tooltip can be customized via the tooltip= argument to the add_markers method. Let’s take a look at this using a simple time series:

[1]:
from astropy import units as u
from astropy.timeseries import TimeSeries
ts = TimeSeries(time_start='2016-03-22T12:30:31', time_delta=3 * u.s, n_samples=10)
ts['flux'] = [10, 11, 9, 10, 2, 3, 5, 12, 11, 10]
ts['error'] = [2, 2.5, 2, 1.5, 2, 2, 1.5, 1.5, 2., 2.5]
ts['quality'] = ['A', 'B', 'A', 'A', 'C', 'C', 'A', 'A', 'C', 'B']
ts
[1]:
TimeSeries length=10
timefluxerrorquality
objectint64float64str1
2016-03-22T12:30:31.000102.0A
2016-03-22T12:30:34.000112.5B
2016-03-22T12:30:37.00092.0A
2016-03-22T12:30:40.000101.5A
2016-03-22T12:30:43.00022.0C
2016-03-22T12:30:46.00032.0C
2016-03-22T12:30:49.00051.5A
2016-03-22T12:30:52.000121.5A
2016-03-22T12:30:55.000112.0C
2016-03-22T12:30:58.000102.5B

Default tooltip

As we’ve seen before, we can make a basic figure with:

[2]:
from aas_timeseries import InteractiveTimeSeriesFigure
[3]:
fig = InteractiveTimeSeriesFigure()
markers = fig.add_markers(time_series=ts, column='flux', label='Flux')
fig.preview_interactive()

If you hover above the points above, you should see a tooltip with the time and flux values.

Disabling the tooltip

You can disable the tooltip by either passing tooltip=False to add_markers or by setting markers.tooltip to False:

[4]:
markers.tooltip = False
fig.preview_interactive()

Customizing columns in tooltip

Instead, we might want to add more columns to the tooltip, such as the quality column in the time series. To do this, you can set tooltip to a tuple or list of column names:

[5]:
markers.tooltip = ['time', 'flux', 'quality']
fig.preview_interactive()

Customizing display labels in tooltip

By default, the name of the fields in the tooltip will be the name of the columns, but it is sometimes desirable to use nicer formatted strings. In this case, you can set tooltip to a dictionary, where the keys are the column names, and the values are the display labels:

[6]:
markers.tooltip = {'time': 'Time (UTC)', 'flux': 'Flux (mJy)', 'quality': 'Quality Flag'}
fig.preview_interactive()