hvPlot.contour#

hvPlot.contour(x=None, y=None, z=None, colorbar=True, levels=5, logz=False, **kwds)[source]#

Line contour plot.

A contour plot displays isolines representing constant values in a 2D scalar field over gridded data.

Reference: https://hvplot.holoviz.org/ref/api/manual/hvplot.hvPlot.contour.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, optional

Whether to display a colorbar. Default is True.

levels: int or list, optional

The number of contour lines to draw or a list of scalar values used to specify the contour levels. Default is 5.

logz: bool, optional

Whether to apply log scaling to the z-axis. Default is False.

**kwdsoptional

Additional keywords arguments are documented in Plotting Options. Run hvplot.help('contour') for the full method documentation.

Returns:
holoviews.element.Contours / Panel object

You 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.

See also

contourf

Filled contour plot.

References

Backend-specific styling options#

alpha, cmap, color, hover_alpha, hover_color, hover_line_alpha, hover_line_cap, hover_line_color, hover_line_dash, hover_line_dash_offset, hover_line_join, hover_line_width, line_alpha, line_cap, line_color, line_dash, line_dash_offset, line_join, line_width, muted, muted_alpha, muted_color, muted_line_alpha, muted_line_cap, muted_line_color, muted_line_dash, muted_line_dash_offset, muted_line_join, muted_line_width, nonselection_alpha, nonselection_color, nonselection_line_alpha, nonselection_line_cap, nonselection_line_color, nonselection_line_dash, nonselection_line_dash_offset, nonselection_line_join, nonselection_line_width, selection_alpha, selection_color, selection_line_alpha, selection_line_cap, selection_line_color, selection_line_dash, selection_line_dash_offset, selection_line_join, selection_line_width, visible

alpha, c, cmap, color, linestyle, linewidth, lw, visible

Examples#

Basic contour lines#

import hvplot.xarray  # noqa
import numpy as np
import xarray as xr

x = y = np.linspace(-10, 10, 200)
X, Y = np.meshgrid(x, y)
Z = 10 * np.exp(-(X**2 + Y**2) / 20)
ds = xr.DataArray(Z, coords=[("y", y), ("x", x)], name="z").to_dataset()

ds.hvplot.contour(x="x", y="y", z="z", levels=10, cmap="viridis")

Let’s use a more realistic dataset and plot contours over a 2D field of air temperature for a single time slice.

import hvplot.xarray # noqa

ds = hvplot.sampledata.air_temperature("xarray").sel(time="2014-02-25 12:00")

ds.hvplot.contour(x='lon', y='lat', levels=20, cmap='viridis_r')

Specify contour levels and colobar label#

You can manually control contour levels by setting levels to a list of values, and add a colorbar label with clabel.

import hvplot.xarray # noqa

ds = hvplot.sampledata.air_temperature("xarray").sel(time="2014-02-25 12:00")

ds.hvplot.contour(
    x='lon', y='lat', z='air', levels=list(range(240, 300, 5)),
    cmap='plasma_r', line_width=1.2, clabel='Air Temperature (K)',
)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.