{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "a68b1c0c", "metadata": { "execution": { "iopub.execute_input": "2025-11-05T13:38:41.835403Z", "iopub.status.busy": "2025-11-05T13:38:41.835295Z", "iopub.status.idle": "2025-11-05T13:38:41.838532Z", "shell.execute_reply": "2025-11-05T13:38:41.838344Z" } }, "outputs": [], "source": [ "import numpy as np\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "b3826f1a-4006-4706-9d90-dc8e022565ed", "metadata": { "execution": { "iopub.execute_input": "2025-11-05T13:38:41.839620Z", "iopub.status.busy": "2025-11-05T13:38:41.839552Z", "iopub.status.idle": "2025-11-05T13:38:41.841281Z", "shell.execute_reply": "2025-11-05T13:38:41.841118Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "4377ea51", "metadata": { "execution": { "iopub.execute_input": "2025-11-05T13:38:41.841976Z", "iopub.status.busy": "2025-11-05T13:38:41.841904Z", "iopub.status.idle": "2025-11-05T13:38:41.844019Z", "shell.execute_reply": "2025-11-05T13:38:41.843847Z" } }, "outputs": [], "source": [ "def time_plot(title, time, y=False):\n", " np.random.seed(0)\n", " value = np.random.normal(loc=-5, scale=6, size=len(time))\n", " d = {'time': time, 'value': value}\n", " if y:\n", " return ggplot(d) + geom_line(aes('value', 'time')) + scale_y_time() + ggtitle(title)\n", " else:\n", " return ggplot(d) + geom_line(aes('time', 'value')) + scale_x_time() + ggtitle(title)\n", "\n", "def serie(start, end, duration, step = None):\n", " if step is None:\n", " step = 1 * duration\n", " \n", " return [v for v in range(start * duration, end * duration, step)]\n", "\n", "MS = 1\n", "SECOND = 1000 * MS\n", "MINUTE = 60 * SECOND\n", "HOUR = 60 * MINUTE" ] }, { "cell_type": "code", "execution_count": 4, "id": "c3497852", "metadata": { "execution": { "iopub.execute_input": "2025-11-05T13:38:41.844676Z", "iopub.status.busy": "2025-11-05T13:38:41.844607Z", "iopub.status.idle": "2025-11-05T13:38:41.882803Z", "shell.execute_reply": "2025-11-05T13:38:41.882574Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " time_plot(\"5 seconds\", serie(0, 5000, MS, step = 5*MS)),\n", " time_plot(\"24 hours\", serie(0, 24, HOUR, step = 30*MINUTE)),\n", " time_plot(\"5 days\", serie(0, 120, HOUR)),\n", " time_plot(\"30 days\", serie(0, 720, HOUR)),\n", " time_plot(\"-30..30 minutes\", serie(-30, 30, MINUTE)),\n", " time_plot(\"-30..30 minutes + scale_y_time()\", serie(-30, 30, MINUTE), y=True)\n", "], ncol=2) + ggsize(960, 900)" ] } ], "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 }