{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "
Title
TriSurface Element
\n", "
Dependencies
Matplotlib
\n", "
Backends
\n", "
Matplotlib
\n", "
Plotly
\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import holoviews as hv\n", "hv.extension('matplotlib')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``TriSurface`` Element renders any collection of 3D points as a surface by applying [Delaunay triangulation](https://en.wikipedia.org/wiki/Delaunay_triangulation). It is therefore useful for plotting an arbitrary collection of datapoints as a 3D surface. Like other 3D elements it supports ``azimuth``, ``elevation`` and ``distance`` plot options to control the camera position:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "y,x = np.mgrid[-5:5, -5:5] * 0.1\n", "heights = np.sin(x**2+y**2)\n", "hv.TriSurface((x.flat,y.flat,heights.flat)).opts(\n", " azimuth=30, elevation=30, fig_size=200)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Like all other colormapped plots we can easily add a ``colorbar`` and control the ``cmap`` of the plot:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "u=np.linspace(0,2*np.pi, 24)\n", "v=np.linspace(-1,1, 8)\n", "u,v=np.meshgrid(u,v)\n", "u=u.flatten()\n", "v=v.flatten()\n", "\n", "#evaluate the parameterization at the flattened u and v\n", "tp=1+0.5*v*np.cos(u/2.)\n", "x=tp*np.cos(u)\n", "y=tp*np.sin(u)\n", "z=0.5*v*np.sin(u/2.)\n", "\n", "surface = hv.TriSurface((x, y, z), label='Moebius band')\n", "surface.opts(cmap='fire', colorbar=True, fig_size=200)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For full documentation and the available style and plot options, use ``hv.help(hv.TriSurface).``" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }