{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "a68b1c0c", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:29.694598Z", "iopub.status.busy": "2024-04-17T07:26:29.694294Z", "iopub.status.idle": "2024-04-17T07:26:30.009803Z", "shell.execute_reply": "2024-04-17T07:26:30.009350Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "from lets_plot import *\n", "LetsPlot.setup_html()\n", "\n", "class ggmatrix():\n", " def __init__(self, plot_width, plot_height):\n", " self.bunch = GGBunch()\n", " self.plot_width = plot_width\n", " self.plot_height = plot_height\n", " \n", " def add(self, col, row, spec):\n", " self.bunch.add_plot(spec, col * self.plot_width, row * self.plot_height, self.plot_width, self.plot_height)\n", " \n", " def show(self):\n", " self.bunch.show()" ] }, { "cell_type": "code", "execution_count": 2, "id": "4377ea51", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:30.011127Z", "iopub.status.busy": "2024-04-17T07:26:30.011008Z", "iopub.status.idle": "2024-04-17T07:26:30.013720Z", "shell.execute_reply": "2024-04-17T07:26:30.013530Z" } }, "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": 3, "id": "c3497852", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:30.014635Z", "iopub.status.busy": "2024-04-17T07:26:30.014561Z", "iopub.status.idle": "2024-04-17T07:26:30.053941Z", "shell.execute_reply": "2024-04-17T07:26:30.053661Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "matrix = ggmatrix(480, 300)\n", "matrix.add(0, 0, time_plot(\"5 seconds\", serie(0, 5000, MS, step = 5*MS)))\n", "matrix.add(1, 0, time_plot(\"24 hours\", serie(0, 24, HOUR, step = 30*MINUTE)))\n", "matrix.add(0, 1, time_plot(\"5 days\", serie(0, 120, HOUR)))\n", "matrix.add(1, 1, time_plot(\"30 days\", serie(0, 720, HOUR)))\n", "matrix.add(0, 2, time_plot(\"-30..30 minutes\", serie(-30, 30, MINUTE)))\n", "matrix.add(1, 2, time_plot(\"-30..30 minutes + scale_y_time()\", serie(-30, 30, MINUTE), y=True))\n", "matrix.show()" ] } ], "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 }