Image duplicates when using ipywidgets.interact to measure distances plotting with imread

24 Views Asked by At

This is my code:

fig, ax = plt.subplots(figsize=(8,8))

def fun(a,aa,b):
    ax.clear()  #Limpia las rectas graficadas
    x = np.linspace(-c, c, num=1400)
    yh = np.full(len(x), a)
    yj = np.full(len(x), aa)
    yv = np.full(len(x), b)

    ax.plot(x, yh, 'green')
    ax.plot(x, yj, 'green')
    ax.plot(yv, x, 'green')
    ax.imshow(imgRGB, cmap='gray',extent =[-c,c,-c,c])

    ax.set_title('Powell Epico')
    ax.set_ylabel('m')
    ax.set_xlabel('m')

    display(fig)
    print(f'Coordenada x1: {a}')
    print(f'Coordenada x2: {aa}')

widgets.interact(fun, a=(-c, c,0.01), aa=(-c,c,0.01), b=(-c, c,0.01))

It plots like this:

enter image description here

It still interacts correctly but only the first coordinated system moves, the lines in the second one remain still. It doesn´t really break the code but it´s certainly uncomfortable. I qant to know what method is creating the duplicate or which method I can use to erase it?

While I´m at it, I´d like to know if there´s a better library for interacting in python. Like, could I get the coordinates just by touching a spot in the image instead of having to manually intersect the lines?

0

There are 0 best solutions below