{ "cells": [ { "cell_type": "markdown", "id": "94918367-ea66-4bc4-9913-c704f45686ee", "metadata": {}, "source": [ "# Plotting Extensions" ] }, { "cell_type": "code", "execution_count": null, "id": "2ce662e1", "metadata": {}, "outputs": [], "source": [ "from hvplot.sample_data import us_crime" ] }, { "cell_type": "markdown", "id": "bd615c60", "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, "id": "78a9f5b8", "metadata": {}, "outputs": [], "source": [ "import hvplot.pandas # This import automatically loads the Bokeh extension." ] }, { "cell_type": "code", "execution_count": null, "id": "615a4574", "metadata": {}, "outputs": [], "source": [ "hvplot.extension('matplotlib', 'plotly') # This call loads the Matplotlib (the active one) and Plotly extensions." ] }, { "cell_type": "code", "execution_count": null, "id": "2d4aa473", "metadata": {}, "outputs": [], "source": [ "us_crime.hvplot(x='Year', y='Violent Crime rate')" ] }, { "cell_type": "markdown", "id": "9724c0af", "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, "id": "66ba89b0", "metadata": {}, "outputs": [], "source": [ "hvplot.output(backend='plotly')\n", "\n", "us_crime.hvplot(x='Year', y='Violent Crime rate')" ] }, { "cell_type": "markdown", "id": "0111ae1a", "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",
"