{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Datetime\n\nThis demo shows how the x-axis of a 1d plot can be a date time.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport datetime\nfrom itom import dataObject\nfrom itom import plot1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Start date with a specific timezone.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "timestamp = datetime.datetime(\n 2022, 5, 6, 12, 23, 5, tzinfo=datetime.timezone(datetime.timedelta(0, -7200))\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a list of ``datetime.datetime`` objects.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "numsteps = 100\ndateList = []\n\nfor x in range(0, numsteps, 15):\n dateList.append(\n timestamp + datetime.timedelta(hours=x)\n )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a ``dataObject`` from the list of ``datetime`` objects.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "dateScale = dataObject([1, len(dateList)], \"datetime\", data=dateList)\n\nvalues = dataObject.randN(dateScale.shape, \"float32\")\n\n[i, h] = plot1(values, dateScale)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "h[\"lineWidth\"] = 3\nh[\"axisLabelRotation\"] = -45\nh[\"axisLabelAlignment\"] = \"AlignLeft\"\nh[\"fillCurve\"] = \"FillFromBottom\"\nh[\"grid\"] = \"GridMajorXY\"\nh[\"axisLabel\"] = \"date\"\nh[\"valueLabel\"] = \"value\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Example with ``numpy datetime`` array.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "dateScale = np.arange('2005-02', '2005-03', dtype='datetime64[D]')\nvalues = dataObject.randN([1, len(dateScale)], \"uint8\")\nplot1(values, dateScale)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }