{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "URL: https://docs.bokeh.org/en/latest/docs/examples/basic/lines/lorenz.html\n", "\n", "Most examples work across multiple plotting backends, this example is also available for:\n", "\n", "* [Bokeh - lorenz_attractor_example](../bokeh/lorenz_attractor_example.ipynb)" ] }, { "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": [ "## Declare the data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from scipy.integrate import odeint\n", "\n", "sigma = 10\n", "rho = 28\n", "beta = 8.0/3\n", "theta = 3 * np.pi / 4\n", "\n", "def lorenz(xyz, t):\n", " x, y, z = xyz\n", " x_dot = sigma * (y - x)\n", " y_dot = x * rho - x * z - y\n", " z_dot = x * y - beta* z\n", " return [x_dot, y_dot, z_dot]\n", "\n", "initial = (-10, -7, 35)\n", "t = np.arange(0, 100, 0.006)\n", "\n", "solution = odeint(lorenz, initial, t)\n", "\n", "x = solution[:, 0]\n", "y = solution[:, 1]\n", "z = solution[:, 2]\n", "xprime = np.cos(theta) * x - np.sin(theta) * y\n", "\n", "paths = zip(np.array_split(xprime, 7), np.array_split(z, 7))\n", "lorenzian = hv.Path([{('x', 'y'): np.array(d).T, 'index': i}\n", " for i, d in enumerate(paths)], vdims='index')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lorenzian.opts(color='index', cmap='Blues', linewidth=1)" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }