{ "cells": [ { "cell_type": "markdown", "id": "7e964342-7b50-4265-a7ee-28fc54e03a76", "metadata": {}, "source": [ "# Parameter `arrow` for `geom_spoke()`\n", "\n", "Note that the lengths of the arrow heads depend on the total lengths of the arrows." ] }, { "cell_type": "code", "execution_count": 1, "id": "5a32162d-828e-4460-a164-071c20886102", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "b0d6ff7e-ea7d-4d5b-9c03-c6a61fbb1aaa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "514279b4-8143-47a7-9795-6bbb5438b8a7", "metadata": {}, "outputs": [], "source": [ "def F(xarray, yarray):\n", " return yarray, -xarray\n", "\n", "def cartesian_to_polar(xarray, yarray):\n", " rarray = np.sqrt(xarray**2 + yarray**2)\n", " return rarray / rarray.max(), np.arctan2(yarray, xarray)" ] }, { "cell_type": "code", "execution_count": 4, "id": "c5a8950a-3845-4e6e-ac24-185ee48a8c10", "metadata": {}, "outputs": [], "source": [ "n = 11\n", "a, b = -5, 5\n", "space = np.linspace(a, b, n)\n", "X, Y = np.meshgrid(space, space)\n", "R, A = cartesian_to_polar(*F(X, Y))\n", "data = dict(x=X.reshape(-1), y=Y.reshape(-1), r=R.reshape(-1), a=A.reshape(-1))" ] }, { "cell_type": "code", "execution_count": 5, "id": "9a9609db-4fc0-41c7-91f1-0501d1c14ac1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(data, aes('x', 'y', color='r')) + \\\n", " geom_spoke(aes(angle='a', radius='r'), \\\n", " arrow=arrow(type='closed', angle=12, length=15)) + \\\n", " scale_color_gradient(low='#3288bd', high='#d53e4f', guide='none') + \\\n", " coord_fixed(xlim=[a, b], ylim=[a, b]) + \\\n", " theme_minimal() + \\\n", " theme(axis_text=element_text(margin=10), axis_title='blank')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.19" } }, "nbformat": 4, "nbformat_minor": 5 }