Plot window won't close when using ginput?

481 views Asked by At

I'm trying to use ginput in order to correct for time-zero in some data that I'm analyzing. I can get the window to pop up and print the point that I click on, but then the window stays open and I am unable to close it. As I am on MacOS, my mouse turns into the spinning beach ball of death when I hover it over any portion of the graph after I click the point I want. I've included sample code below.

import xarray as xr 
import matplotlib
import matplotlib.pyplot as plt

scan = bb.load_data(aux_file, data_file) #self-written load-in function

early_time = scan.coords["t"][25:75]
wl = scan[25:75, 250]


plt.plot(early_time, wl)

time_zero = plt.ginput(1, timeout=-1)
print(time_zero)
plt.close("all")

I'm sure there must be something simple that I'm missing but I cannot find anything that has the same issue after several hours of searching.

1

There are 1 answers

0
Haiyang Tang On

When importing matplotlib, try this and set the backend to QT4Agg to see if it works:

import matplotlib   
matplotlib.use('QT4Agg')    
import matplotlib.pyplot as plt 

uv = plt.ginput(x)   
plt.close()