{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "URL: https://docs.bokeh.org/en/latest/docs/examples/basic/annotations/legend.html\n", "\n", "Most examples work across multiple plotting backends, this example is also available for:\n", "\n", "* [Bokeh - legend_example](../bokeh/legend_example.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import holoviews as hv\n", "\n", "hv.extension('matplotlib')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Defining data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = np.linspace(0, 4*np.pi, 100)\n", "y = np.sin(x)\n", "\n", "scatter1 = hv.Scatter((x, y), label='sin(x)')\n", "scatter2 = hv.Scatter((x, y*2), label='2*sin(x)')\n", "scatter3 = hv.Scatter((x, y*3), label='3*sin(x)')\n", "\n", "curve1 = hv.Curve(scatter1)\n", "curve2 = hv.Curve(scatter2)\n", "curve3 = hv.Curve(scatter3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "example1 = scatter1 * scatter2.opts(color='orange') * scatter3.opts(color='green')\n", "example2 = (\n", " scatter1 * curve1 * curve2.opts(color='orange', linestyle='--') *\n", " scatter3.opts(color='green', marker='s') * curve3)\n", "\n", "example1.relabel(\"Legend Example\") + example2.relabel(\"Another Legend Example\")" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }