import matplotlib.pyplot as plt import numpy as np def tvplus(array,**kwargs): """ tvplus function as IDL to click and get coord as well as point values array: float 2-D to be plotted **kwarg: vmin, vmax: floats min and max values of the plot cmap: str , colorbar to be used """ ## define event when clicking the mouse def onclick(event): print(F"[y:{int(event.ydata)}, x:{int(event.xdata)}] = {array[int(event.ydata),int(event.xdata)]}") ## print, min and max of field print(F"Array min: {np.nanmin(array)}, max: {np.nanmax(array)}") ## default values of vmin, vmax and cmap vmin = kwargs.get('vmin', np.nanmin(array)) vmax = kwargs.get('vmax', np.nanmax(array)) cmap = kwargs.get('cmap', 'jet') ## plot the data in a simple way fig,ax = plt.subplots() m=ax.pcolormesh(array,cmap=cmap,vmin=vmin, vmax=vmax) fig.colorbar(m,ax=ax) fig.canvas.mpl_connect('button_press_event', onclick) plt.show()