{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from hvplot.sample_data import us_crime" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "hvPlot allows to generate plots with three different plotting extensions: [Bokeh](https://docs.bokeh.org), [Matplotlib](https://matplotlib.org/) and [Plotly](https://plotly.com/). Support for Maplotlib and Plotly was added in version 0.8.0, before which Bokeh was the only option available and is as such kept as the default plotting extension.\n", "\n", "## Loading plotting extensions\n", "\n", "Importing hvPlot accessors as shown throughout the documentation (e.g. `import hvplot.pandas`, `import hvplot.xarray`, ...) loads by default the Bokeh plotting extension. The `extension` function can be used after this first import to additionally load the Matplotlib and Plotly plotting extensions, or just one of them. The currently active extension is the first one passed to `extension()`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import hvplot.pandas # This import automatically loads the Bokeh extension.\n", "hvplot.extension('matplotlib', 'plotly') # This call loads the Matplotlib (the active one) and Plotly extensions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "us_crime.hvplot(x='Year', y='Violent Crime rate')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Switching the plotting extension\n", "\n", "The `output` function allows to switch the plotting extension by setting the `backend` parameter. It must be called **after** importing an accessor (e.g. `import hvplot.pandas`) and calling to `extension`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hvplot.output(backend='plotly')\n", "\n", "us_crime.hvplot(x='Year', y='Violent Crime rate')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
extension
function could also be used to switch the plotting extension. You should however prefer output
as any call to extension
actually internally loads code in the output of the cell where it is executed, which can significantly increase the notebook size if extension
is called in multiple cells.\n",
"