{ "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": { "execution": { "iopub.execute_input": "2025-07-17T16:54:16.260953Z", "iopub.status.busy": "2025-07-17T16:54:16.260456Z", "iopub.status.idle": "2025-07-17T16:54:16.263680Z", "shell.execute_reply": "2025-07-17T16:54:16.263470Z" } }, "outputs": [], "source": [ "import numpy as np\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "6a9633c3-f3fa-43b6-bd85-5c55169c223b", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T16:54:16.264781Z", "iopub.status.busy": "2025-07-17T16:54:16.264679Z", "iopub.status.idle": "2025-07-17T16:54:16.266516Z", "shell.execute_reply": "2025-07-17T16:54:16.266348Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "8208a625-fa5f-40e2-83dc-f7a033cb051e", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T16:54:16.267292Z", "iopub.status.busy": "2025-07-17T16:54:16.267166Z", "iopub.status.idle": "2025-07-17T16:54:16.269757Z", "shell.execute_reply": "2025-07-17T16:54:16.269572Z" } }, "outputs": [], "source": [ "def cartesian_to_polar(xarray, yarray, rscale):\n", " rarray = np.sqrt(xarray**2 + yarray**2)\n", " return rarray / rarray.max() * rscale, np.arctan2(yarray, xarray)\n", "\n", "def get_data(n, a, b, vector_field):\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", " R, A, Z = vector_field(X, Y, d)\n", " z = [None] * X.shape[0] * X.shape[1] if Z is None else Z.reshape(-1)\n", " return dict(x=X.reshape(-1), y=Y.reshape(-1), r=R.reshape(-1), a=A.reshape(-1), z=z)\n", "\n", "def vector_field(f):\n", " def field(xarray, yarray, d):\n", " return *cartesian_to_polar(*f(xarray, yarray), d), None\n", " return field\n", "\n", "def gradient_field(f):\n", " def field(xarray, yarray, d):\n", " Z = f(xarray, yarray)\n", " return *cartesian_to_polar(*reversed(np.gradient(Z, d)), d), Z\n", " return field" ] }, { "cell_type": "markdown", "id": "6c2e3974-aad5-4f62-bac4-6afa1327bf6f", "metadata": {}, "source": [ "#### 1. Plot Vector Field" ] }, { "cell_type": "code", "execution_count": 4, "id": "bb63ad78-fce0-40e0-b31d-870f71cab410", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T16:54:16.270490Z", "iopub.status.busy": "2025-07-17T16:54:16.270421Z", "iopub.status.idle": "2025-07-17T16:54:16.272033Z", "shell.execute_reply": "2025-07-17T16:54:16.271854Z" } }, "outputs": [], "source": [ "n = 11\n", "a, b = -5, 5\n", "vector_field_data = get_data(n, a, b, vector_field(lambda xarray, yarray: (yarray, -xarray)))" ] }, { "cell_type": "code", "execution_count": 5, "id": "a5e48193-c5f1-49c3-9b83-c83b46cf4943", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T16:54:16.272696Z", "iopub.status.busy": "2025-07-17T16:54:16.272626Z", "iopub.status.idle": "2025-07-17T16:54:16.304362Z", "shell.execute_reply": "2025-07-17T16:54:16.304077Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "