{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple Way to Draw a Curve" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:09:29.507346Z", "iopub.status.busy": "2026-01-27T17:09:29.507276Z", "iopub.status.idle": "2026-01-27T17:09:29.510334Z", "shell.execute_reply": "2026-01-27T17:09:29.510041Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "from lets_plot import *\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:09:29.527426Z", "iopub.status.busy": "2026-01-27T17:09:29.527328Z", "iopub.status.idle": "2026-01-27T17:09:29.528916Z", "shell.execute_reply": "2026-01-27T17:09:29.528532Z" } }, "outputs": [], "source": [ "BG_CLR = '#253494'\n", "EC_CLR = '#ffffcc'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:09:29.529690Z", "iopub.status.busy": "2026-01-27T17:09:29.529613Z", "iopub.status.idle": "2026-01-27T17:09:29.531108Z", "shell.execute_reply": "2026-01-27T17:09:29.530895Z" } }, "outputs": [], "source": [ "# Curve parametrized equation\n", "def ec_eq(*, a=0, b=0):\n", " return lambda x, y: y ** 2 - x ** 3 - a * x - b" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:09:29.531803Z", "iopub.status.busy": "2026-01-27T17:09:29.531732Z", "iopub.status.idle": "2026-01-27T17:09:29.533206Z", "shell.execute_reply": "2026-01-27T17:09:29.532984Z" } }, "outputs": [], "source": [ "def level(X, Y, *, eq, c=1):\n", " level_map = lambda z: np.exp(-c * np.abs(z))\n", " return level_map(eq(X, Y))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:09:29.533797Z", "iopub.status.busy": "2026-01-27T17:09:29.533728Z", "iopub.status.idle": "2026-01-27T17:09:29.536012Z", "shell.execute_reply": "2026-01-27T17:09:29.535798Z" } }, "outputs": [], "source": [ "dx, dy = 1.0 / 30.0, 1.0 / 10.0\n", "\n", "x = np.arange(-3, 3, dx)\n", "y = np.arange(-3, 3, dy)\n", "X, Y = np.meshgrid(x, y)\n", "curve_eq = ec_eq(a=-1, b=0)\n", "Z = level(X, Y, eq=curve_eq, c=10)\n", "\n", "df = pd.DataFrame(dict(x=X.reshape(-1), y=Y.reshape(-1), z=Z.reshape(-1)))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:09:29.536686Z", "iopub.status.busy": "2026-01-27T17:09:29.536614Z", "iopub.status.idle": "2026-01-27T17:09:29.538599Z", "shell.execute_reply": "2026-01-27T17:09:29.538371Z" } }, "outputs": [], "source": [ "theme_layer = scale_color_gradient(low=BG_CLR, high=EC_CLR) + scale_fill_gradient(low=BG_CLR, high=EC_CLR) + \\\n", " xlim(df.x.min(), df.x.max()) + ylim(df.y.min(), df.y.max()) + ggsize(600, 450) + \\\n", " theme_void() + theme(panel_background=element_rect(color=BG_CLR, fill=BG_CLR))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:09:29.539353Z", "iopub.status.busy": "2026-01-27T17:09:29.539281Z", "iopub.status.idle": "2026-01-27T17:09:29.574646Z", "shell.execute_reply": "2026-01-27T17:09:29.574415Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "