{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "
Title
Surface 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", "from holoviews import opts\n", "\n", "hv.extension('matplotlib')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "``Surface`` is used for a set of gridded points whose associated value dimension represents samples from a continuous surface. ``Surface`` is equivalent to an ``Image`` type and supports all the same data formats, including simply NumPy arrays with associated ``bounds`` and other gridded data formats such as xarray.\n", "\n", "Rendering a large can often be quite expensive, using ``rstride`` and ``cstride`` we can draw a coarser surface. We can also control the ``azimuth``, ``elevation`` and ``distance`` as plot options to control the camera angle:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "surface = hv.Surface(np.sin(np.linspace(0,100*np.pi*2,10000)).reshape(100,100))\n", "\n", "surface.opts(opts.Surface(azimuth=30, elevation=30, rstride=20, cstride=2, cmap='plasma'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition to a simple surface plots, the matplotlib surface plot also supports other related ``plot_type`` modes including ``'wireframe'`` and ``'contour'`` plots:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "xs = np.arange(-4, 4, 0.25)\n", "ys = np.arange(-4, 4, 0.25)\n", "X, Y = np.meshgrid(xs, ys)\n", "R = np.sqrt(X**2 + Y**2)\n", "Z = np.sin(R)\n", "\n", "surface = hv.Surface((xs, ys, Z), label='Surface')\n", "wireframe = surface.relabel('Wireframe').opts(plot_type='wireframe')\n", "contour = surface.relabel('Contour').opts(plot_type='contour')\n", "\n", "(surface + wireframe + contour).opts(\n", " opts.Layout(fig_size=150, hspace=0.1),\n", " opts.Surface(azimuth=60, cmap='fire'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For full documentation and the available style and plot options, use ``hv.help(hv.Surface).``" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }