Contour plots

Contour plot support is limited to picking the individual LineCollections, which are directly registered with the axes and thus picked up by mplcursors.cursor (QuadContourSets are not even artists, which make them hard to handle without additional special-casing). It remains possible to retrieve the z value and add it manually to the annotation, though.

import numpy as np
import matplotlib.pyplot as plt
import mplcursors


fig, ax = plt.subplots()
cf = ax.contour(np.random.random((10, 10)))
cursor = mplcursors.cursor()

def on_add(sel):
    ann = sel.annotation
    # `cf.collections.index(sel.artist)` is the index of the selected line
    # among all those that form the contour plot.
    # `cf.cvalues[...]` is the corresponding value.
        ann.get_text(), cf.cvalues[cf.collections.index(sel.artist)]))

Gallery generated by Sphinx-Gallery