holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

Contours for QuadMesh Elements #4913

Open ea42gh opened 3 years ago

ea42gh commented 3 years ago

Describe alternatives you've considered

My current workaround is to interpolate the data:

def interpolated_scalogram( x,y, d, method='nearest'):
    from scipy.interpolate import griddata
    xi,yi = np.meshgrid(np.linspace(np.min(x), np.max(x), len(x)),
                        np.linspace(np.min(y), np.max(y), len(y)))
    di = griddata( (x.ravel(), y.ravel()), d.ravel(), (xi.ravel(), yi.ravel()), method=method )
    return xi,yi, di.reshape(d.shape)

def estimate_levels( d, l = np.sin(0.5*np.pi*np.linspace( 0.1, 1, 5, endpoint=False)), decimals=2 ):
    dmin,dmax = np.min(d), np.max(d)
    return np.round( [dmin + t*(dmax-dmin) for t in l], decimals)

def plot_qmesh_contours(t,freqs, tfr, l = None, filled=True, overlaid=True, img_args={}, contour_args={} ):
    from holoviews.operation import contours
    ti,freqsi,tfri = interpolated_scalogram( *np.meshgrid(t, freqs), tfr, 'cubic')
    img = hv.Image( (ti[0,:], freqsi[:,0], tfri), ["Time", "Frequency"] )\
      .opts(cmap="Viridis", width=400,show_grid=False)\
      .opts( **img_args )
    if l is None: l = estimate_levels(tfr)
    return contours(img, levels=l, filled=filled, overlaid=overlaid).opts("Contours", **contour_args)

Additional context

Add any other context or screenshots about the feature request here. wvlt

jlstevens commented 3 years ago

Having contours support non-regular image data is a reasonable request. Either we should issue a message saying that we don't support non-regular grids (and why) or we could interpolate ourselves when necessary (maybe issuing a warning to say that interpolation is being used to estimate the contours).