{ "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", "* [Matplotlib - legend_example](../matplotlib/legend_example.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import holoviews as hv\n", "hv.extension('bokeh')" ] }, { "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)').opts(color='orange')\n", "scatter3 = hv.Scatter((x, y*3), label='3*sin(x)').opts(color='green')\n", "scatter4 = hv.Scatter(scatter3).opts(line_color='green', marker='square', fill_alpha=0, size=5)\n", "\n", "curve1 = hv.Curve(scatter1)\n", "curve2 = hv.Curve(scatter2).opts(line_dash=(4, 4), color='orange')\n", "curve3 = hv.Curve(scatter3).opts(color='orange')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "example1 = scatter1 * scatter2 * scatter3\n", "example2 = scatter1 * curve1 * curve2 * scatter4 * 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 }