{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "
Title
Points 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": [ "The ``Points`` element visualizes as markers placed in a space of two independent variables, traditionally denoted *x* and *y*. In HoloViews, the names ``'x'`` and ``'y'`` are used as the default ``key_dimensions`` of the element. We can see this from the default axis labels when visualizing a simple ``Points`` element:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%opts Points (color='k' marker='+' size=10)\n", "np.random.seed(12)\n", "coords = np.random.rand(50,2)\n", "hv.Points(coords)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here both the random *x* values and random *y* values are *both* considered to be the 'data' with no dependency between them (compare this to how [``Scatter``](./Scatter.ipynb) elements are defined). You can think of ``Points`` as simply marking positions in some two-dimensional space that can be sliced by specifying a 2D region-of-interest:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%opts Points (color='k' marker='+' size=10)\n", "hv.Points(coords) + hv.Points(coords)[0.6:0.8,0.2:0.5]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Although the simplest ``Points`` element simply mark positions in a two-dimensional space without any associated value this doesn't mean value dimensions aren't supported. Here is an example with two additional quantities for each point, declared as the ``value_dimension``s *z* and α visualized as the color and size of the dots, respectively:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%opts Points [color_index=2 size_index=3 scaling_factor=50]\n", "np.random.seed(10)\n", "data = np.random.rand(100,4)\n", "\n", "points = hv.Points(data, vdims=['z', 'size'])\n", "points + points[0.3:0.7, 0.3:0.7].hist()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the right subplot, the ``hist`` method is used to show the distribution of samples along the first value dimension we added (*z*).\n", "\n", "\n", "The marker shape specified above can be any supported by [matplotlib](http://matplotlib.org/api/markers_api.html), e.g. ``s``, ``d``, or ``o``; the other options select the color and size of the marker. For convenience with the [bokeh backend](../../../user_guide/Plotting_with_Bokeh.ipynb), the matplotlib marker options are supported using a compatibility function in HoloViews." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note**: Although the ``Scatter`` element is superficially similar to the [``Points``](./Points.ipynb) element (they can generate plots that look identical), the two element types are semantically quite different. The fundamental difference is that [``Points``](./Points.ipynb) are used to visualize data where the *y* variable is *dependent*. This semantic difference also explains why the histogram generated by ``hist`` call above visualizes the distribution of a different dimension than it does for [``Scatter``](./Scatter.ipynb).\n", "\n", "This difference means that ``Points`` naturally combine elements that express independent variables in two-dimensional space, for instance [``Raster``](./Raster.ipynb) types such as [``Image``](./Image.ipynb). Similarly, ``Scatter`` expresses a dependent relationship in two-dimensions and combine naturally with ``Chart`` types such as [``Curve``](./Curve.ipynb).\n", "\n", "\n", "For full documentation and the available style and plot options, use ``hv.help(hv.Points).``" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }