{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f45649f5-4213-47b1-b1a4-7a24573a890f", "metadata": {}, "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": {}, "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": { "scrolled": true }, "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(),\n", " p + coord_polar() + theme(legend_position='none'),\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.8.15" } }, "nbformat": 4, "nbformat_minor": 5 }