hvPlot.image#
- hvPlot.image(x=None, y=None, z=None, colorbar=True, **kwds)[source]#
Image plot
You can use image to display for example geographic data with independent latitude and longitude fields and a third dependent field.
Reference: https://hvplot.holoviz.org/ref/api/manual/hvplot.hvPlot.image.html
Plotting options: https://hvplot.holoviz.org/ref/plotting_options/index.html
- Parameters:
- xstring, optional
The coordinate variable along the x-axis
- ystring, optional
The coordinate variable along the y-axis
- zstring, optional
The data variable to plot
- colorbar: boolean
Whether to display a colorbar
- **kwdsoptional
Additional keywords arguments are documented in Plotting Options. Run
hvplot.help('image')
for the full method documentation.
- Returns:
holoviews.element.Image
/ Panel objectYou can print the object to study its composition and run:
import holoviews as hv hv.help(the_holoviews_object)
to learn more about its parameters and options.
References
Backend-specific styling options#
alpha, cmap, muted, visible
alpha, clims, cmap, filterrad, interpolation, norm, visible
Examples#
Basic image plot#
colorbar
is True by default.
import hvplot.xarray # noqa
import numpy as np
import xarray as xr
x = np.linspace(0, 10, 100)
y = np.linspace(0, 5, 50)
X, Y = np.meshgrid(x, y)
data = np.exp(np.sin(X) * np.cos(Y) * 3)
ds = xr.Dataset({"value": (["y", "x"], data)}, coords={"y": y, "x": x})
ds.hvplot.image()
Air temperature image grid#
Let’s display an image from a real-world dataset.
import hvplot.xarray # noqa
ds = hvplot.sampledata.air_temperature("xarray").sel(time="2014-02-25 12:00")
ds.hvplot.image(x="lon", y="lat", z="air", cmap="viridis", data_aspect=1)
Use of groupby
#
When the grid has more dimensions, like time
in the example below, widgets are automatically created to explore further the dataset. This is equivalent to setting the groupby
to the remaining dimension(s).
import hvplot.xarray # noqa
ds = hvplot.sampledata.air_temperature("xarray").isel(time=[0, 1])
ds.hvplot.image(
x="lon", y="lat", z="air", groupby="time",
frame_width=400, data_aspect=1, dynamic=False,
)
Use of logz
#
import hvplot.xarray # noqa
import numpy as np
import xarray as xr
x = np.linspace(0, 10, 100)
y = np.linspace(0, 5, 50)
X, Y = np.meshgrid(x, y)
data = np.exp(np.sin(X) * np.cos(Y) * 3) * 100
ds = xr.Dataset({"value": (["y", "x"], data)}, coords={"y": y, "x": x})
ds.hvplot.image(logz=True)
Image vs. Quadmesh#
The constructor of the HoloViews Image
element, object returned by an image
call, attempts to validate the input data by ensuring it is regularly sampled. In some cases, your data may be not be regularly sampled to a sufficiently high precision in which case you will see an exception recommending the use of the Quadmesh
element instead. If you see this message and are sure that the Image
element is appropriate, you can set the rtol
value globally using hv.config.image_rtol
in to allow a higher deviation in sample spacing than the default of 10e-6. If not, use the quadmesh
method.
import hvplot.xarray # noqa
ds = hvplot.sampledata.air_temperature("xarray").sel(time="2014-02-25 12:00")
# Emulate irregular grid
ds.coords["lat"] = ds.coords["lat"]**2
ds.hvplot.image(x="lon", y="lat", z="air", cmap="blues", width=400, height=400)
WARNING:param.Image00677: Image dimension lat is not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.
WARNING:param.Image00677: Image dimension lat is not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.