{ "cells": [ { "cell_type": "markdown", "id": "65a47279-f0c5-4367-8323-b4a9b1e96891", "metadata": {}, "source": [ "# Polar Heatmap" ] }, { "cell_type": "code", "execution_count": 1, "id": "f45649f5-4213-47b1-b1a4-7a24573a890f", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T12:17:15.968392Z", "iopub.status.busy": "2024-04-26T12:17:15.968392Z", "iopub.status.idle": "2024-04-26T12:17:18.419118Z", "shell.execute_reply": "2024-04-26T12:17:18.419118Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "from scipy.interpolate import griddata\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "3d04285b-e631-41c0-9dc7-a09b3ad68e61", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T12:17:18.419118Z", "iopub.status.busy": "2024-04-26T12:17:18.419118Z", "iopub.status.idle": "2024-04-26T12:17:18.434797Z", "shell.execute_reply": "2024-04-26T12:17:18.434797Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "48bee431-7aa0-4fb8-8026-9ca157b5a190", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T12:17:18.434797Z", "iopub.status.busy": "2024-04-26T12:17:18.434797Z", "iopub.status.idle": "2024-04-26T12:17:19.399913Z", "shell.execute_reply": "2024-04-26T12:17:19.399913Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "max_r = 100\n", "max_theta = 2.0 * np.pi\n", "number_points = 5_000\n", "np.random.seed(42)\n", "\n", "grid_r, grid_theta = np.meshgrid(\n", " np.linspace(0, max_r, 200), # r\n", " np.linspace(0.0, max_theta, 100) # theta\n", ")\n", "\n", "points = np.random.rand(number_points, 2) * [max_r, max_theta]\n", "values = points[:,0] * np.sin(points[:,1])**2 * np.cos(points[:,1])**2\n", "data = griddata(points, values, (grid_r, grid_theta), method='cubic',fill_value=0)\n", "\n", "df = {\n", " 'x': grid_theta.flatten(), \n", " 'y': grid_r.flatten(), \n", " 'z': data.flatten()\n", "}\n", "\n", "p = ggplot(df) + \\\n", " geom_tile(aes('x', 'y', color='z', fill='z'), size=1, tooltips='none') + \\\n", " scale_brewer(['color', 'fill'], palette='Spectral', direction=-1) + \\\n", " theme(axis_title=element_blank())\n", "\n", "gggrid([\n", " p + coord_cartesian() + ggtitle(\"Rectangular Heatmap\"),\n", " p + coord_polar() + theme(legend_position='none') + ggtitle(\"Polar Heatmap\"),\n", "])" ] } ], "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.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }