{ "cells": [ { "cell_type": "markdown", "id": "c284f51c-72ac-4e19-981d-43fc79570b16", "metadata": {}, "source": [ "# `geom_spoke()`" ] }, { "cell_type": "code", "execution_count": 1, "id": "45bd1cf4-dcec-460e-8a92-8e7cb9b15ea6", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "6a9633c3-f3fa-43b6-bd85-5c55169c223b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "3dcaba37-31b4-49c8-b2c4-7b9f9d57e453", "metadata": {}, "outputs": [], "source": [ "def get_data(n, a, b, f):\n", " d = (b - a) / (n - 1)\n", " xrange = np.linspace(a, b, n)\n", " yrange = np.linspace(a, b, n)\n", " X, Y = np.meshgrid(xrange, yrange)\n", " x, y = X.reshape(-1), Y.reshape(-1)\n", " Z = f(X, Y)\n", " z = Z.reshape(-1)\n", " dY, dX = np.gradient(Z, d)\n", " R = np.sqrt(dX**2 + dY**2)\n", " normalized_R = R / R.max() * d\n", " A = np.arctan2(dY, dX)\n", " radius, angle = normalized_R.reshape(-1), A.reshape(-1)\n", " return pd.DataFrame({'x': x, 'y': y, 'z': z, 'radius': radius, 'angle': angle})" ] }, { "cell_type": "code", "execution_count": 4, "id": "37cdc646-d4cc-44ce-bff2-71306299c3e5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(441, 5)\n" ] }, { "data": { "text/html": [ "| \n", " | x | \n", "y | \n", "z | \n", "radius | \n", "angle | \n", "
|---|---|---|---|---|---|
| 0 | \n", "-6.283185 | \n", "-6.283185 | \n", "1.000000 | \n", "0.478721 | \n", "-0.314159 | \n", "
| 1 | \n", "-5.654867 | \n", "-6.283185 | \n", "1.587785 | \n", "0.396934 | \n", "-0.381905 | \n", "
| 2 | \n", "-5.026548 | \n", "-6.283185 | \n", "1.951057 | \n", "0.204153 | \n", "-0.810479 | \n", "
| 3 | \n", "-4.398230 | \n", "-6.283185 | \n", "1.951057 | \n", "0.204153 | \n", "-2.331114 | \n", "
| 4 | \n", "-3.769911 | \n", "-6.283185 | \n", "1.587785 | \n", "0.396934 | \n", "-2.759688 | \n", "