Example#

You can create a DraggableLine on any interactive plot by passing it the ax and initial positions.

# choose backend if in a jupyter notebook
%matplotlib widget

from __future__ import annotations
import matplotlib.pyplot as plt
from mpl_draggable_line import DraggableLine, DraggableVLine


fig, ax = plt.subplots()

init_x = [50, 0.5]
init_y = [0.25, 0.5]
dl = DraggableLine(ax, init_x, init_y)

Callbacks#

You can connect functions to receive callbacks whenver the line is moved using the on_line_changed function.

def my_callback(x: list[float, float], y: list[float, float]):
    print(x, y)

dl.on_line_changed(my_callback)