{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "
Title
Div Element
\n", "
Dependencies
Bokeh
\n", "
Backends
Bokeh
\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import holoviews as hv\n", "hv.extension('bokeh', 'matplotlib')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "``Div`` elements may be used to display arbitrary HTML and embed it in a bokeh plot. It supports all standard HTML tags and may be sized using the usual ``width`` and ``height`` plot options.\n", "\n", "As a simple example we can create a figure with some heading tags an image tag and a figure caption which includes LaTeX rendering:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hv.Div(\"\"\"\n", "

Div

\n", "

A simple demo

\n", "\n", "
\n", "\n", "
Fig 1: This is a figure caption with $LaTeX$
\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since many libraries (including HoloViews) support HTML output directly we can use the element to quickly and easily embed additional information about a dataset. To illustrate this we create an ``Image``, convert it to a 3D Surface element and render it to HTML with the matplotlib backend. Additionally we use the ``dframe`` method on the ``Image`` and then use ``describe`` on the resulting DataFrame to compute a summary table, which we also convert to HTML. Now we can add both next to our Image plot:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "X = np.arange(-5, 5, 0.25)\n", "Y = np.arange(-5, 5, 0.25)\n", "X, Y = np.meshgrid(X, Y)\n", "R = np.sqrt(X**2 + Y**2)\n", "Z = np.sin(R)\n", "img = hv.Image(Z)\n", "\n", "# Render matplotlib surface plot to HTML\n", "surface = hv.Surface(img)\n", "surface_html = hv.renderer('matplotlib').html(surface)\n", "surface_div = hv.Div(surface_html)\n", "\n", "# Generate HTML summary table from pandas dataframe\n", "df_html = img.dframe()[['z']].describe().to_html()\n", "df_div = hv.Div(\"
\"+df_html+\"
\")\n", "\n", "img + surface_div + df_div.opts(width=200)" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }