Quadmesh

Title
QuadMesh Element
Dependencies
Matplotlib
Backends
Matplotlib
Bokeh
In [1]:
import numpy as np
import holoviews as hv
hv.extension('matplotlib')

The basic QuadMesh is a 2D grid of bins specified as x-/y-values specifying a regular sampling or edges, with arbitrary sampling and an associated 2D array containing the bin values. Here is a simple QuadMesh with logarithmic sampling along the 'x' dimensions:

In [2]:
n = 8  # Number of bins in each direction
xs = np.logspace(1, 3, n)
ys = np.linspace(1, 10, n)
zs = np.arange((n-1)**2).reshape(n-1, n-1)
hv.QuadMesh((xs, ys, zs))
Out[2]:

The coordinate system of a QuadMesh is defined by the bin edges, therefore any index falling into a binned region will return the appropriate value. As the bin edges have continuous values, you can use non-linear axes such as log axes:

In [3]:
%%opts QuadMesh [xticks=[10, 100,1000]] QuadMesh.LogScale [logx=True]
hv.QuadMesh((xs, ys, zs), group='LinearScale') + hv.QuadMesh((xs, ys, zs), group='LogScale')
Out[3]:

Unlike Image objects, slices must be inclusive of the bin edges but otherwise the slicing semantics are the same. The reason for this difference is that QuadMesh is really a two-dimensional histogram and when slicing, you only want to see the bins that fall within the specified slice ranges.

In the next example, we specify a slice along the x- and y-axis to extract the lower corner and we set the z-dimension range to maintain the full color range of the colormap:

In [4]:
qmesh = hv.QuadMesh((xs, ys, zs))
qmesh[20:400, :8].redim.range(z=qmesh.range('z'))
Out[4]:

To use an interactive hover tool to inspect the sample values, you can use QuadMesh with the hover tool in the Bokeh backend


Download this notebook from GitHub (right-click to download).