{ "cells": [ { "cell_type": "markdown", "id": "24893578-8106-4ce5-874c-eea8011b1a18", "metadata": {}, "source": [ "# Plotting Time Series\n", "\n", "Lets-Plot handles all temporal data types through a unified \"datetime\" scale (excluding duration/timedelta types, which are handled by the \"time\" scale). This is in contrast to R's ggplot2, which provides separate \"date\", \"time\", and \"datetime\" scales.\n", "\n", "**Supported temporal data types:**\n", "\n", "- Python `time` objects (time of day)\n", "- Python `date` objects\n", "- Python `datetime` objects (both naive and timezone-aware)\n", "- NumPy `datetime64` objects\n", "- Pandas Series with timezone information\n", "- Polars Series with timezone information" ] }, { "cell_type": "code", "execution_count": 1, "id": "ffb7ff9c-c23a-4aa7-a222-cafe7943b269", "metadata": {}, "outputs": [], "source": [ "from datetime import datetime, date, time, timedelta, timezone\n", "\n", "import numpy as np\n", "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "f81e51b9-bc23-4d18-bc96-f7029f647dbb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "195e8880-08f0-40ee-b591-b643535ba608", "metadata": {}, "outputs": [], "source": [ "def squiggle(x):\n", " return np.sin(3 * x) / (x * (np.cos(x) + 2))" ] }, { "cell_type": "code", "execution_count": 4, "id": "d0f9940b-3602-4cfe-b352-e82c0b47a5e3", "metadata": {}, "outputs": [], "source": [ "N = 50\n", "xs = np.linspace(1, 25, N)\n", "ys = [squiggle(x) for x in xs ]" ] }, { "cell_type": "markdown", "id": "8228e825-a0b3-484b-ac8a-7f4b9006ab16", "metadata": {}, "source": [ "#### Local Time\n", "\n", "Python `time` objects represent time-of-day values (local/clock time) independent of any specific date. \n", "\n", "The datetime scale renders these with default tooltips and scale breaks optimized for hours or smaller time units." ] }, { "cell_type": "code", "execution_count": 5, "id": "dedf32b6-2cd6-4800-8cb8-73220c3aa5fe", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "