{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "
Title
Scatter3D Element
\n", "
Dependencies
Matplotlib
\n", "
Backends
Matplotlib
Plotly
\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import holoviews as hv\n", "from holoviews import dim, opts\n", "\n", "hv.extension('plotly')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "``Scatter3D`` plots represents three-dimensional coordinates which are specified as key dimensions (`kdims`, default `kdims` are x, y, z). The points can be given a `marker`, `color` and `size`. Additionally a `colorbar` can be added.\n", "\n", "``Scatter3D`` plots are therefore very similar to [``Points``](Points.ipynb) and [``Scatter``](Scatter.ipynb) types, but have one additional coordinate dimension.\n", "\n", "Like other 3D elements the camera angle can be controlled using `azimuth`, `elevation` and `distance` plot options" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "y,x = np.mgrid[-5:5, -5:5] * 0.1\n", "z=np.sin(x**2+y**2)\n", "\n", "hv.Scatter3D((x.flat,y.flat,z.flat)).opts(cmap='fire', color='z', size=5, colorbar=True, height=600, width=600)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also provide your data in a container and specify the `kdims` to use." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = pd.DataFrame(dict(lat=x.flat, lon=y.flat, height=z.flat))\n", "\n", "hv.Scatter3D(data, kdims=[\"lat\", \"lon\", \"height\"]).opts(cmap='blues', color='height', size=3, colorbar=True, height=600, width=600, colorbar_opts={'title': 'height (m)'}, marker=\"diamond\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Just like all regular 2D elements, ``Scatter3D`` types can be overlaid and will follow the default color cycle: \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(hv.Scatter3D(np.random.randn(100,4), vdims='Size') * hv.Scatter3D(np.random.randn(100,4)+2, vdims='Size')).opts(\n", " opts.Scatter3D(size=(5+dim('Size'))*2, marker='diamond', height=600, width=600)\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For full documentation and the available style and plot options, use ``hv.help(hv.Scatter3D).``" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hv.help(hv.Scatter3D)" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }