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]:
| time | flux | error | quality |
|---|---|---|---|
| object | int64 | float64 | str1 |
| 2016-03-22T12:30:31.000 | 10 | 2.0 | A |
| 2016-03-22T12:30:34.000 | 11 | 2.5 | B |
| 2016-03-22T12:30:37.000 | 9 | 2.0 | A |
| 2016-03-22T12:30:40.000 | 10 | 1.5 | A |
| 2016-03-22T12:30:43.000 | 2 | 2.0 | C |
| 2016-03-22T12:30:46.000 | 3 | 2.0 | C |
| 2016-03-22T12:30:49.000 | 5 | 1.5 | A |
| 2016-03-22T12:30:52.000 | 12 | 1.5 | A |
| 2016-03-22T12:30:55.000 | 11 | 2.0 | C |
| 2016-03-22T12:30:58.000 | 10 | 2.5 | B |
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()