{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#### **Title**: Area Element\n", "\n", "**Dependencies**: Plotly\n", "\n", "**Backends**: [Bokeh](../bokeh/Area.ipynb), [Matplotlib](../matplotlib/Area.ipynb), [Plotly](./Area.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import holoviews as hv\n", "hv.extension('plotly')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "``Area`` elements are ``Curve`` elements where the area below the line is filled. Like ``Curve`` elements, ``Area`` elements are used to display the development of quantitative values over an interval or time period. ``Area`` Elements may also be stacked to display multiple data series in a cumulative fashion over the value dimension.\n", "\n", "The data of an ``Area`` Element should be tabular with one key dimension representing the samples over the interval or the timeseries and one or two value dimensions. A single value dimension will fill the area between the curve and the x-axis, while two value dimensions will fill the area between the curves. See the [Tabular Datasets](../../../user_guide/08-Tabular_Datasets.ipynb) user guide for supported data formats, which include arrays, pandas dataframes and dictionaries of arrays." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Area under the curve\n", "\n", "By default the Area Element draws just the area under the curve, i.e. the region between the curve and the origin." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "xs = np.linspace(0, np.pi*4, 40)\n", "hv.Area((xs, np.sin(xs)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Area between curves\n", "\n", "When supplied a second value dimension the area is defined as the area between two curves." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "X = np.linspace(0,3,200)\n", "Y = X**2 + 3\n", "Y2 = np.exp(X) + 2\n", "Y3 = np.cos(X)\n", "hv.Area((X, Y, Y2), vdims=['y', 'y2']) * hv.Area((X, Y, Y3), vdims=['y', 'y3'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Stacked areas \n", "\n", "Areas are also useful to visualize multiple variables changing over time, but in order to be able to compare them the areas need to be stacked. To do this, use the ``Area.stack`` classmethod to stack multiple ``Area`` elements in an (Nd)Overlay.\n", "\n", "In this example we will generate a set of 5 arrays representing percentages and create an ``Overlay`` of them. Then we simply call the ``stack`` method with this overlay to get a stacked area chart.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "values = np.random.rand(5, 20)\n", "percentages = (values/values.sum(axis=0)).T*100\n", "\n", "value_dim = hv.Dimension('value', unit='%')\n", "\n", "overlay = hv.Overlay([hv.Area(percentages[:, i], vdims=value_dim) for i in range(5)])\n", "overlay + hv.Area.stack(overlay)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For full documentation and the available style and plot options, use ``hv.help(hv.Area).``" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }