{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "
Title
HSV Element
\n", "
Dependencies
Bokeh
\n", "
Backends
Bokeh
Matplotlib
\n", "
\n", "
" ] }, { "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": [ "HoloViews makes it trivial to work in any color space that can be converted to ``RGB`` by making a simple subclass of ``RGB`` as appropriate. For instance, we also provide the HSV (hue, saturation, value) color space, which is useful for plotting cyclic data (as the Hue) along with two additional dimensions (controlling the saturation and value of the color, respectively).\n", "\n", "Like other raster based Element types ``HSV`` accepts gridded data, which may be supplied as a simple array ``NxMx3`` ndarray representing hue, saturation and value channels along with bounds or explicit array coordinates. See the [Gridded Datasets](../../../user_guide/08-Gridded_Datasets.ipynb) user guide to see the accepted data formats." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x,y = np.mgrid[-50:51, -50:51] * 0.1\n", "h = 0.5 + np.sin(0.2*(x**2+y**2)) / 2.0\n", "s = 0.5*np.cos(y*3)+0.5\n", "v = 0.5*np.cos(x*3)+0.5\n", "\n", "hsv = hv.HSV(np.dstack([h, s, v]))\n", "hsv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can see how this is created from the original channels:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%opts Image (cmap='gray')\n", "hsv[..., 'H'].relabel('H') + hsv[..., 'S'].relabel('S') + hsv[..., 'V'].relabel('V')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An ``HSV`` Element can also easily be converted to an ``RGB`` Element using the ``rgb`` property:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(hsv.rgb)\n", "hsv.rgb[..., 'R'] + hsv.rgb[..., 'G'] + hsv.rgb[..., 'B']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For full documentation and the available style and plot options, use ``hv.help(hv.HSV).``" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }