.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/misc/tooltips_custom.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_misc_tooltips_custom.py: Tooltips Customization ====================== Customize the information displayed in a tooltip. This example uses the Iris dataset and sets the tooltip to display the species and cluster label of the point that is being hovered by the mouse pointer. .. GENERATED FROM PYTHON SOURCE LINES 8-54 .. image-sg:: /_gallery/misc/images/sphx_glr_tooltips_custom_001.webp :alt: tooltips custom :srcset: /_gallery/misc/images/sphx_glr_tooltips_custom_001.webp :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/fastplotlib/fastplotlib/fastplotlib/graphics/features/_base.py:18: UserWarning: casting float64 array to float32 warn(f"casting {array.dtype} array to float32") | .. code-block:: Python # test_example = false import fastplotlib as fpl from sklearn.cluster import AgglomerativeClustering from sklearn import datasets figure = fpl.Figure(size=(700, 560)) dataset = datasets.load_iris() data = dataset["data"] agg = AgglomerativeClustering(n_clusters=3) agg.fit_predict(data) scatter_graphic = figure[0, 0].add_scatter( data=data[:, :-1], # use only xy data sizes=15, cmap="Set1", cmap_transform=agg.labels_ # use the labels as a transform to map colors from the colormap ) def tooltip_info(ev) -> str: # get index of the scatter point that is being hovered index = ev.pick_info["vertex_index"] # get the species name target = dataset["target"][index] cluster = agg.labels_[index] info = f"species: {dataset['target_names'][target]}\ncluster: {cluster}" # return this string to display it in the tooltip return info figure.tooltip_manager.register(scatter_graphic, custom_info=tooltip_info) figure.show() if __name__ == "__main__": print(__doc__) fpl.loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.552 seconds) .. _sphx_glr_download__gallery_misc_tooltips_custom.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tooltips_custom.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tooltips_custom.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: tooltips_custom.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_