{ "cells": [ { "cell_type": "markdown", "id": "e831935b", "metadata": {}, "source": [ "# psview\n", "An example how to display PS, EPS, PDF files in canvas.\n", "To load a PS file in a TCanvas, the ghostscript program needs to be install.\n", "- On most unix systems it is installed by default.\n", "- On Windows it has to be installed from http://pages.cs.wisc.edu/~ghost/\n", " also the place where gswin32c.exe sits should be added in the PATH. One\n", " way to do it is:\n", " 1. Start the Control Panel\n", " 2. Double click on System\n", " 3, Open the \"Advanced\" tab\n", " 4. Click on the \"Environment Variables\" button\n", " 5. Find \"Path\" in \"System variable list\", click on it.\n", " 6. Click on the \"Edit\" button.\n", " 7. In the \"Variable value\" field add the path of gswin32c\n", " (after a \";\") it should be something like:\n", " \"C:\\Program Files\\gs\\gs8.13\\bin\"\n", " 8. click \"OK\" as much as needed.\n", "\n", "\n", "\n", "\n", "**Author:** Valeriy Onoutchin \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:37 PM." ] }, { "cell_type": "markdown", "id": "b867e23d", "metadata": {}, "source": [ "set to batch mode -> do not display graphics" ] }, { "cell_type": "code", "execution_count": 1, "id": "8b2d2b11", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:26.635838Z", "iopub.status.busy": "2026-05-19T20:37:26.635705Z", "iopub.status.idle": "2026-05-19T20:37:27.142737Z", "shell.execute_reply": "2026-05-19T20:37:27.142291Z" } }, "outputs": [], "source": [ "gROOT->SetBatch(1);" ] }, { "cell_type": "markdown", "id": "63bbef26", "metadata": {}, "source": [ "create a PostScript file" ] }, { "cell_type": "code", "execution_count": 2, "id": "e1faf21b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:27.162308Z", "iopub.status.busy": "2026-05-19T20:37:27.162172Z", "iopub.status.idle": "2026-05-19T20:37:27.368509Z", "shell.execute_reply": "2026-05-19T20:37:27.368050Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Info in : eps file feynman.eps has been created\n" ] } ], "source": [ "TString dir = gROOT->GetTutorialDir();\n", "dir.Append(\"/visualisation/graphics/feynman.C\");\n", "gROOT->Macro(dir);\n", "gPad->Print(\"feynman.eps\");" ] }, { "cell_type": "markdown", "id": "3bcdf4c8", "metadata": {}, "source": [ "back to graphics mode" ] }, { "cell_type": "code", "execution_count": 3, "id": "a58af1ee", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:27.372371Z", "iopub.status.busy": "2026-05-19T20:37:27.372254Z", "iopub.status.idle": "2026-05-19T20:37:27.582260Z", "shell.execute_reply": "2026-05-19T20:37:27.581662Z" } }, "outputs": [], "source": [ "gROOT->SetBatch(0);" ] }, { "cell_type": "markdown", "id": "4b52f666", "metadata": {}, "source": [ "create an image from PS file" ] }, { "cell_type": "code", "execution_count": 4, "id": "42b34699", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:27.584089Z", "iopub.status.busy": "2026-05-19T20:37:27.583961Z", "iopub.status.idle": "2026-05-19T20:37:27.812207Z", "shell.execute_reply": "2026-05-19T20:37:27.800646Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning in : GhostScript is not available\n", "Error in : Can't figure out DISPLAY, set it manually\n", "In case you run a remote ssh session, restart your ssh session with:\n", "=========> ssh -Y\n", "Error in : Can't figure out DISPLAY, set it manually\n", "In case you run a remote ssh session, restart your ssh session with:\n", "=========> ssh -Y\n", "Error in : no image set\n" ] } ], "source": [ "TImage *ps = TImage::Open(\"feynman.eps\");\n", "\n", "if (!ps) {\n", " printf(\"GhostScript (gs) program must be installed\\n\");\n", " return;\n", "}\n", "\n", "new TCanvas(\"psexam\", \"Example how to display PS file in canvas\", 600, 400);\n", "TLatex *tex = new TLatex(0.06, 0.9, \"The picture below has been loaded from a PS file:\");\n", "tex->Draw();\n", "\n", "TPad *eps = new TPad(\"eps\", \"eps\", 0., 0., 1., 0.75);\n", "eps->Draw();\n", "eps->cd();\n", "ps->Draw(\"xxx\");" ] }, { "cell_type": "markdown", "id": "304a0d08", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "9604e23c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:27.820749Z", "iopub.status.busy": "2026-05-19T20:37:27.820575Z", "iopub.status.idle": "2026-05-19T20:37:28.030472Z", "shell.execute_reply": "2026-05-19T20:37:28.030028Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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 }