{ "cells": [ { "cell_type": "markdown", "id": "a3f7409d", "metadata": {}, "source": [ "# twoscales\n", "Two fully interactive scales in web canvas.\n", "\n", "Shows two scales drawing for X or Y axis\n", "Several objects can be drawn on the frame and one can select which axis is used for drawing\n", "Y+ means that Y drawn on right frame side, X+ - X will be drawn on top frame side\n", "Several objects can be add to the frame and associated with normal or opposite axis drawing -\n", "like using \"same,Y+\" option\n", "\n", "Functionality available only in web-based graphics\n", "\n", "\n", "\n", "\n", "**Author:** Sergey Linev \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:39 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "fcd76e13", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:39:04.960465Z", "iopub.status.busy": "2026-05-19T20:39:04.960356Z", "iopub.status.idle": "2026-05-19T20:39:05.430389Z", "shell.execute_reply": "2026-05-19T20:39:05.429597Z" } }, "outputs": [], "source": [ "auto hpe = new TH1F(\"hpe\", \"Use left and right side for Y scale drawing\", 100, 0, 10);\n", "hpe->GetYaxis()->SetTitle(\"Expo\");\n", "\n", "auto hpg = new TH1F(\"hpg\", \"Gaus distribution\", 100, 0, 10);\n", "hpg->GetYaxis()->SetTitle(\"#color[2]{Gaus1} / #color[3]{Gaus2}\");\n", "hpg->GetYaxis()->SetAxisColor(kRed);\n", "hpg->SetLineColor(kRed);\n", "\n", "auto hpg2 = new TH1F(\"hpg2\", \"Narrow gaus distribution\", 100, 0, 10);\n", "hpg2->SetLineColor(kGreen);\n", "\n", "for (int i = 0; i < 25000; i++) {\n", " hpe->Fill(gRandom->Exp(1.));\n", " hpg->Fill(gRandom->Gaus(4, 1.));\n", " if (i % 10 == 0)\n", " hpg2->Fill(gRandom->Gaus(8, 0.25));\n", "}\n", "\n", "auto gr1 = new TGraph(1000);\n", "auto gr2 = new TGraph(10000);\n", "for (int i = 0; i < 10000; i++) {\n", " auto x = 20. + i / 100.;\n", " if ((i >= 2000) && (i < 3000))\n", " gr1->SetPoint(i - 2000, x, 1.5 + TMath::Sin(x));\n", " gr2->SetPoint(i, x, 3.5 + TMath::Sin(x));\n", "}\n", "\n", "gr1->SetMinimum(0);\n", "gr1->SetMaximum(5);\n", "gr1->SetTitle(\"Tow graphs sharing same Y scale, but using different X scales\");\n", "gr1->GetXaxis()->SetTitle(\"Graph1\");\n", "\n", "gr2->SetLineColor(kBlue);\n", "gr2->GetXaxis()->SetAxisColor(kBlue);\n", "gr2->GetXaxis()->SetTitle(\"Graph2\");\n", "gr2->GetXaxis()->SetTitleColor(kBlue);\n", "\n", "gStyle->SetStatX(0.88);\n", "\n", "auto c1 = new TCanvas(\"c1\", \"Twoscales example\", 1200, 800);\n", "\n", "if (!gROOT->IsBatch() && !c1->IsWeb())\n", " ::Warning(\"twoscales.cxx\", \"macro may not work without enabling web-based canvas\");\n", "\n", "c1->Divide(1, 2);\n", "\n", "c1->GetPad(1)->Add(hpe); // normal drawing\n", "c1->GetPad(1)->Add(hpg, \"Y+\"); // draw independent Y axis on right side\n", "c1->GetPad(1)->Add(hpg2, \"same,Y+\"); // use Y drawn on right side\n", "\n", "c1->GetPad(2)->SetTopMargin(0.2); // need more space on top\n", "c1->GetPad(2)->Add(gr1, \"AL\"); // draw as line\n", "c1->GetPad(2)->Add(gr2, \"AL,X+\"); // draw as line with independent X axis on top of the frame" ] }, { "cell_type": "markdown", "id": "e2ddb86d", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 2, "id": "91b27308", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:39:05.432225Z", "iopub.status.busy": "2026-05-19T20:39:05.432104Z", "iopub.status.idle": "2026-05-19T20:39:05.667911Z", "shell.execute_reply": "2026-05-19T20:39:05.667186Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "