#!/usr/bin/env python # coding: utf-8 # # What is Holoviz way of getting coordinate values of clicked points? # In Matlab, we would use [ginput](https://www.mathworks.com/help/matlab/ref/ginput.html): # > [x,y] = ginput(n) allows you to identify the coordinates of n points within Cartesian, polar, or geographic axes. To choose a point, move your cursor to the desired location and press either a mouse button or a key on the keyboard. Press the Return key to stop before all n points are selected. MATLABĀ® returns the coordinates of your selected points. If there are no axes, calling ginput creates a Cartesian axes object. # In[1]: import xarray as xr import hvplot.xarray from holoviews.streams import PointDraw import holoviews as hv from holoviews import opts # In[2]: url = 's3://landsat-pds/c1/L8/042/034/LC08_L1TP_042034_20170616_20170629_01_T1/LC08_L1TP_042034_20170616_20170629_01_T1_B4.TIF' # In[3]: da = xr.open_rasterio(url).squeeze('band') # In[4]: image = da.hvplot.image(rasterize=True, cmap='turbo', data_aspect=1) # In[5]: points = hv.Points([[da.x.mean().values, da.y.mean().values]]) point_stream = PointDraw(source=points) # In[6]: (image * points).opts( opts.Points(size=20, color='black', marker='x')) # In[7]: if point_stream.data: display(point_stream.element.dframe()) # In[ ]: