How to use mplcursors - 10 common examples

To help you get started, we’ve selected a few mplcursors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
def test_nan(ax, plot_args, click, targets):
    ax.plot(*plot_args)
    cursor = mplcursors.cursor()
    _process_event("__mouse_click__", ax, click, 1)
    assert len(cursor.selections) == len(ax.texts) == len(targets)
    for sel, target in zip(cursor.selections, targets):
        assert sel.target == approx(target)
github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
def test_image_subclass(ax):
    # Cannot move around `PcolorImage`s.
    ax.pcolorfast(np.arange(3) ** 2, np.arange(3) ** 2, np.zeros((2, 2)))
    cursor = mplcursors.cursor()
    with pytest.warns(UserWarning):
        _process_event("__mouse_click__", ax, (1, 1), 1)
    assert len(cursor.selections) == 0
github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
def test_hover(ax, hover):
    l1, = ax.plot([0, 1])
    l2, = ax.plot([1, 2])
    cursor = mplcursors.cursor(hover=hover)
    _process_event("motion_notify_event", ax, (.5, .5), 1)
    assert len(cursor.selections) == 0  # No trigger if mouse button pressed.
    _process_event("motion_notify_event", ax, (.5, .5))
    assert cursor.selections[0].artist == l1
    _process_event("motion_notify_event", ax, (.5, 1))
    assert bool(cursor.selections) == (hover == HoverMode.Persistent)
    _process_event("motion_notify_event", ax, (.5, 1.5))
    assert cursor.selections[0].artist == l2
github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
    "hover", [True, HoverMode.Persistent, 2, HoverMode.Transient])
def test_hover(ax, hover):
    l1, = ax.plot([0, 1])
    l2, = ax.plot([1, 2])
    cursor = mplcursors.cursor(hover=hover)
    _process_event("motion_notify_event", ax, (.5, .5), 1)
    assert len(cursor.selections) == 0  # No trigger if mouse button pressed.
    _process_event("motion_notify_event", ax, (.5, .5))
    assert cursor.selections[0].artist == l1
    _process_event("motion_notify_event", ax, (.5, 1))
    assert bool(cursor.selections) == (hover == HoverMode.Persistent)
    _process_event("motion_notify_event", ax, (.5, 1.5))
    assert cursor.selections[0].artist == l2
github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
def test_steps_index():
    index = _pick_info.Index(0, .5, .5)
    assert np.floor(index) == 0 and np.ceil(index) == 1
    assert str(index) == "0.(x=0.5, y=0.5)"
github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
def test_containerartist(ax):
    artist = _pick_info.ContainerArtist(ax.errorbar([], []))
    str(artist)
    repr(artist)
github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
def test_selection_identity_comparison():
    sel0, sel1 = [Selection(artist=None,
                            target=np.array([0, 0]),
                            dist=0,
                            annotation=None,
                            extras=[])
                  for _ in range(2)]
    assert sel0 != sel1
github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
def _internal_warnings(record):
    return [
        warning for warning in record
        if Path(mplcursors.__file__).parent in Path(warning.filename).parents]
github anntzer / mplcursors / tests / test_mplcursors.py View on Github external
def cleanup():
    with mpl.rc_context({"axes.unicode_minus": False}):
        try:
            yield
        finally:
            mplcursors.__warningregistry__ = {}
            plt.close("all")
github afeinstein20 / eleanor / ELLIE_v1.2 / markGaia.py View on Github external
def plot_with_hover(tpf, gaiaXY, gaiaID, gaiaMAG, ticID, tmag):
    fig, ax = plt.subplots()

    ax.imshow(tpf.flux[0], origin='lower')
    sc = ax.scatter(gaiaXY[0], gaiaXY[1], c='k', s=10)

    plt.xlim([-0.5,8.5])
    plt.ylim([-0.5,8.5])

    mplcursors.cursor(sc).connect(
        "add", lambda sel: sel.annotation.set_text("TIC ID = {}\nTmag = {}\nGaia ID = {}\nGmag = {}".format(ticID[sel.target.index],
                                                                                                            tmag[sel.target.index],
                                                                                                            gaiaID[sel.target.index], 
                                                                                                            gaiaMAG[sel.target.index])))
    plt.show()