{ "cells": [ { "cell_type": "markdown", "id": "6d8bf173", "metadata": {}, "source": [ "# gr108_timeSeriesFromCSV\n", "with data read from a text file containing the SWAN usage\n", "statistics during July 2017.\n", "\n", "\n", "\n", "**Author:** Danilo Piparo, Olivier Couet \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:38 PM." ] }, { "cell_type": "markdown", "id": "39c3fc7d", "metadata": {}, "source": [ "Open the data file. This csv contains the usage statistics of a CERN IT\n", "service, SWAN, during two weeks. We would like to plot this data with\n", "ROOT to draw some conclusions from it." ] }, { "cell_type": "code", "execution_count": 1, "id": "616193e3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:21.313669Z", "iopub.status.busy": "2026-05-19T20:38:21.313541Z", "iopub.status.idle": "2026-05-19T20:38:21.634218Z", "shell.execute_reply": "2026-05-19T20:38:21.633450Z" } }, "outputs": [], "source": [ "TString dir = gROOT->GetTutorialDir();\n", "dir.Append(\"/visualisation/graphs/\");\n", "dir.ReplaceAll(\"/./\", \"/\");\n", "FILE *f = fopen(Form(\"%sSWAN2017.dat\", dir.Data()), \"r\");" ] }, { "cell_type": "markdown", "id": "ae688ad9", "metadata": {}, "source": [ "Create the time graph. In this example, we don't specify anything about it,\n", "and data points will be added with SetPoint (the first point has index 0)" ] }, { "cell_type": "code", "execution_count": 2, "id": "94e63894", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:21.636242Z", "iopub.status.busy": "2026-05-19T20:38:21.636028Z", "iopub.status.idle": "2026-05-19T20:38:21.843697Z", "shell.execute_reply": "2026-05-19T20:38:21.843010Z" } }, "outputs": [], "source": [ "auto g = new TGraph();\n", "g->SetTitle(\"SWAN Users during July 2017;Time;Number of Sessions\");" ] }, { "cell_type": "markdown", "id": "f3f137f6", "metadata": {}, "source": [ "Read the data and fill the graph with time along the X axis and number\n", "of users along the Y axis" ] }, { "cell_type": "code", "execution_count": 3, "id": "db55cae6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:21.845794Z", "iopub.status.busy": "2026-05-19T20:38:21.845667Z", "iopub.status.idle": "2026-05-19T20:38:22.057529Z", "shell.execute_reply": "2026-05-19T20:38:22.056846Z" } }, "outputs": [], "source": [ "char line[80];\n", "float v;\n", "char dt[20];\n", "int i = 0;\n", "while (fgets(line, 80, f)) {\n", " sscanf(&line[20], \"%f\", &v);\n", " strncpy(dt, line, 18);\n", " dt[19] = '\\0';\n", " g->SetPoint(i, TDatime(dt).Convert(), v);\n", " i++;\n", "}\n", "fclose(f);" ] }, { "cell_type": "markdown", "id": "c61516d3", "metadata": {}, "source": [ "Draw the graph" ] }, { "cell_type": "code", "execution_count": 4, "id": "e4162ef6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:22.059730Z", "iopub.status.busy": "2026-05-19T20:38:22.059595Z", "iopub.status.idle": "2026-05-19T20:38:22.272426Z", "shell.execute_reply": "2026-05-19T20:38:22.271800Z" } }, "outputs": [], "source": [ "auto c = new TCanvas(\"c\", \"c\", 950, 500);\n", "c->SetLeftMargin(0.07);\n", "c->SetRightMargin(0.04);\n", "c->SetGrid();\n", "g->SetLineWidth(3);\n", "g->SetLineColor(kBlue);\n", "g->Draw(\"al\");\n", "g->GetYaxis()->CenterTitle();" ] }, { "cell_type": "markdown", "id": "8ffb4270", "metadata": {}, "source": [ "Make the X axis labelled with time" ] }, { "cell_type": "code", "execution_count": 5, "id": "29371597", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:22.274175Z", "iopub.status.busy": "2026-05-19T20:38:22.274060Z", "iopub.status.idle": "2026-05-19T20:38:22.485910Z", "shell.execute_reply": "2026-05-19T20:38:22.485314Z" } }, "outputs": [], "source": [ "auto xaxis = g->GetXaxis();\n", "xaxis->SetTimeDisplay(1);\n", "xaxis->CenterTitle();\n", "xaxis->SetTimeFormat(\"%a %d\");\n", "xaxis->SetTimeOffset(0);\n", "xaxis->SetNdivisions(-219);\n", "xaxis->SetLimits(TDatime(2017, 7, 3, 0, 0, 0).Convert(), TDatime(2017, 7, 22, 0, 0, 0).Convert());\n", "xaxis->SetLabelSize(0.025);\n", "xaxis->CenterLabels();" ] }, { "cell_type": "markdown", "id": "e3e12c78", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 6, "id": "efa4c1c8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:22.487677Z", "iopub.status.busy": "2026-05-19T20:38:22.487546Z", "iopub.status.idle": "2026-05-19T20:38:22.723982Z", "shell.execute_reply": "2026-05-19T20:38:22.723324Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "