hvPlot#

Familiar and high-level API for data exploration and visualization

hvPlot diagram

.hvplot() for a more versatile and powerful .plot() API

By replacing .plot() by .hvplot() you get an interactive Bokeh plot.

import hvplot.pandas  # noqa
from bokeh.sampledata.penguins import data as df

df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', by='species')

.hvplot() supports many data structures of the PyData ecosystem on top of Pandas:

import hvplot.xarray  # noqa
import xarray as xr

xr_ds = xr.tutorial.open_dataset('air_temperature').load().sel(time='2013-06-01 12:00')
xr_ds.hvplot()
xarray support
import dask
import hvplot.dask  # noqa

df_dask = dask.dataframe.from_pandas(df, npartitions=2)
df_dask.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', by='species')
dask support
import geopandas as gpd
import hvplot.pandas  # noqa

gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
gdf.hvplot(global_extent=True, tiles=True)
geopandas support
import hvplot.networkx as hvnx
import networkx as nx

G = nx.petersen_graph()
hvnx.draw(G, with_labels=True)
networkx support
import hvplot.intake  # noqa
from hvplot.sample_data import catalogue as cat

cat.us_crime.hvplot.line(x='Year', y='Violent Crime rate')
intake support
import hvplot.streamz  # noqa
from streamz.dataframe import Random

df_streamz = Random(interval='200ms', freq='50ms')
df_streamz.hvplot()
streamz support

.hvplot() can also generate plots with Matplotlib or Plotly.

import hvplot.pandas
import pandas
from bokeh.sampledata.penguins import data as df

hvplot.extension('matplotlib')

df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', by='species')
matplotlib as a plotting backend
import hvplot.pandas
import pandas
from bokeh.sampledata.penguins import data as df

hvplot.extension('plotly')

df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', by='species')
plotly as a plotting backend

.hvplot() sources its power in the HoloViz ecosystem. With HoloViews you get the ability to easily layout and overlay plots, with Panel you can get more interactive control of your plots with widgets, with DataShader you can visualize and interactively explore very large data, and with GeoViews you can create geographic plots.

import hvplot.pandas  # noqa
from hvplot.sample_data import us_crime as df

plot1 = df.hvplot(x='Year', y='Violent Crime rate', width=400)
plot2 = df.hvplot(x='Year', y='Burglary rate', width=400)
plot1 + plot2
laying out plots
import hvplot.pandas  # noqa
import pandas
from bokeh.sampledata.penguins import data

df = data.groupby('species')['bill_length_mm'].describe().sort_values('mean')
df.hvplot.scatter(y='mean') * dff.hvplot.errorbars(y='mean', yerr1='std')
overlaying plots
import hvplot.pandas  # noqa
from bokeh.sampledata.penguins import data as df

df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', groupby='island', widget_location='top')
more control with widgets
import hvplot.pandas  # noqa
from hvplot.sample_data import catalogue as cat

df = cat.airline_flights.read()
df.hvplot.scatter(x='distance', y='airtime', rasterize=True, cnorm='eq_hist', width=500)
visualize and explore large data
import hvplot.xarray  # noqa
import xarray as xr, cartopy.crs as crs

air_ds = xr.tutorial.open_dataset('air_temperature').load()
air_ds.air.sel(time='2013-06-01 12:00').hvplot.quadmesh(
    'lon', 'lat', projection=crs.Orthographic(-90, 30), project=True,
    global_extent=True, cmap='viridis', coastline=True
)
geographic plots

.interactive() to turn data pipelines into widget-based interactive applications

By starting a data pipeline with .interactive() you can then inject widgets into an extract and transform data pipeline. The pipeline output dynamically updates with widget changes, making data exploration in Jupyter notebooks in particular a lot more efficient.

import hvplot.pandas  # noqa
import panel as pn
from bokeh.sampledata.penguins import data as df

w_sex = pn.widgets.MultiSelect(name='Sex', value=['MALE'], options=['MALE', 'FEMALE'])
w_body_mass = pn.widgets.FloatSlider(name='Min body mass', start=2700, end=6300, step=50)

dfi = df.interactive(loc='left')
dfi.loc[(dfi['sex'].isin(w_sex)) & (dfi['body_mass_g'] > w_body_mass)]['bill_length_mm'].describe()
interactive app from pandas
import hvplot.xarray  # noqa
import panel as pn
import xarray as xr

w_time = pn.widgets.IntSlider(name='time', start=0, end=10)

da = xr.tutorial.open_dataset('air_temperature').air
da.interactive.isel(time=w_time).mean().item() - da.mean().item()
interactive app from xarray

.interactive() supports displaying the pipeline output with .hvplot().

import hvplot.xarray  # noqa
import panel as pn
import xarray as xr

da = xr.tutorial.open_dataset('air_temperature').air
w_quantile = pn.widgets.FloatSlider(name='quantile', start=0, end=1)
w_time = pn.widgets.IntSlider(name='time', start=0, end=10)

da.interactive(loc='left') \
.isel(time=w_time) \
.quantile(q=w_quantile, dim='lon') \
.hvplot(ylabel='Air Temperature [K]', width=500)
interactive pipeline with an hvplot output

explorer() to explore data in a web application

The Explorer is a Panel web application that can be displayed in a Jupyter notebook and that can be used to quickly create customized plots.

import hvplot.pandas
from bokeh.sampledata.penguins import data as df

hvexplorer = hvplot.explorer(df)
hvexplorer
explore data with the hvplot explorer