{ "cells": [ { "cell_type": "markdown", "id": "1b587651", "metadata": {}, "source": [ "# hist021_TH2_reverse_axis\n", "\n", "\n", "\n", "\n", "**Author:** 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:12 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "e79d6ac1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:24.197354Z", "iopub.status.busy": "2026-05-19T20:12:24.197231Z", "iopub.status.idle": "2026-05-19T20:12:24.517917Z", "shell.execute_reply": "2026-05-19T20:12:24.517142Z" } }, "outputs": [], "source": [ "void ReverseXAxis(TH1 *h);\n", "void ReverseYAxis(TH1 *h);" ] }, { "cell_type": "markdown", "id": "aea19c14", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 2, "id": "f8cb4495", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:24.520187Z", "iopub.status.busy": "2026-05-19T20:12:24.520066Z", "iopub.status.idle": "2026-05-19T20:12:24.528000Z", "shell.execute_reply": "2026-05-19T20:12:24.527420Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void ReverseXAxis(TH1 *h)\n", "{\n", " // Remove the current axis\n", " h->GetXaxis()->SetLabelOffset(999);\n", " h->GetXaxis()->SetTickLength(0);\n", "\n", " // Redraw the new axis\n", " gPad->Update();\n", " TGaxis *newaxis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(), gPad->GetUxmin(), gPad->GetUymin(),\n", " h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax(), 510, \"-\");\n", " newaxis->SetLabelOffset(-0.03);\n", " newaxis->Draw();\n", "}" ] }, { "cell_type": "markdown", "id": "e7e65da3", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 3, "id": "04eb329c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:24.529632Z", "iopub.status.busy": "2026-05-19T20:12:24.529504Z", "iopub.status.idle": "2026-05-19T20:12:24.533031Z", "shell.execute_reply": "2026-05-19T20:12:24.532423Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void ReverseYAxis(TH1 *h)\n", "{\n", " // Remove the current axis\n", " h->GetYaxis()->SetLabelOffset(999);\n", " h->GetYaxis()->SetTickLength(0);\n", "\n", " // Redraw the new axis\n", " gPad->Update();\n", " TGaxis *newaxis = new TGaxis(gPad->GetUxmin(), gPad->GetUymax(), gPad->GetUxmin() - 0.001, gPad->GetUymin(),\n", " h->GetYaxis()->GetXmin(), h->GetYaxis()->GetXmax(), 510, \"+\");\n", " newaxis->SetLabelOffset(-0.03);\n", " newaxis->Draw();\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "id": "0932f448", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:24.534478Z", "iopub.status.busy": "2026-05-19T20:12:24.534364Z", "iopub.status.idle": "2026-05-19T20:12:24.738512Z", "shell.execute_reply": "2026-05-19T20:12:24.737806Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "TH2F *hpxpy = new TH2F(\"hpxpy\", \"py vs px\", 40, -4, 4, 40, -4, 4);\n", "Float_t px, py;\n", "TRandom r;\n", "for (Int_t i = 0; i < 25000; i++) {\n", " r.Rannor(px, py);\n", " hpxpy->Fill(px, py);\n", "}\n", "TCanvas *c1 = new TCanvas(\"c1\");\n", "hpxpy->Draw(\"colz\");\n", "ReverseXAxis(hpxpy);\n", "ReverseYAxis(hpxpy);" ] }, { "cell_type": "markdown", "id": "035e4ce5", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "78e72183", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:24.740125Z", "iopub.status.busy": "2026-05-19T20:12:24.740004Z", "iopub.status.idle": "2026-05-19T20:12:24.943963Z", "shell.execute_reply": "2026-05-19T20:12:24.943501Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }