{ "cells": [ { "cell_type": "markdown", "id": "188d2814-6a99-49a1-8968-abd9b3e503ea", "metadata": {}, "source": [ "# Scale Time" ] }, { "cell_type": "code", "execution_count": 1, "id": "a68b1c0c", "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:04:19.288151Z", "iopub.status.busy": "2026-01-27T17:04:19.288056Z", "iopub.status.idle": "2026-01-27T17:04:19.290777Z", "shell.execute_reply": "2026-01-27T17:04:19.290492Z" } }, "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": "2026-01-27T17:04:19.291557Z", "iopub.status.busy": "2026-01-27T17:04:19.291483Z", "iopub.status.idle": "2026-01-27T17:04:19.293119Z", "shell.execute_reply": "2026-01-27T17:04:19.292833Z" } }, "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": "2026-01-27T17:04:19.294064Z", "iopub.status.busy": "2026-01-27T17:04:19.293977Z", "iopub.status.idle": "2026-01-27T17:04:19.296375Z", "shell.execute_reply": "2026-01-27T17:04:19.296007Z" } }, "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": "2026-01-27T17:04:19.297104Z", "iopub.status.busy": "2026-01-27T17:04:19.297035Z", "iopub.status.idle": "2026-01-27T17:04:19.342074Z", "shell.execute_reply": "2026-01-27T17:04:19.341726Z" } }, "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 }