# Exercise 2: Adding error bars to a histogram **(5 minutes)** We're still plotting the **`chi2`** histogram as a solid curve. Most of the time, your supervisor will want to see histograms with errors. Revise the script to draw the histograms with error bars. (Here's a {ref}`hint `.) :::{warning} The histogram may not be immediately visible, because all the points are squeezed into the left-hand side of the plot. We'll investigate the reason why in a subsequent exercise. ::: :::{figure-md} chi2-errors-python-fig :class: align-center chi2 histogram What I get when I plot chi2 with errors bars turned on. ::: (making-a-plot)= ::::{admonition} This plot required special handling :class: note In case you're interested, the code below is how I made the above plot: - I learned to use `gPad` to access the temporary histogram from reading the documentation for [`TTree::Draw()`](https://root.cern/doc/master/classTTree.html). - I learned about `SetTitleOffset` by reading the [`TAxis`](https://root.cern/doc/master/classTAxis.html) documentation. - This led me to the list of [`TGaxis`](https://root.cern/doc/master/classTGaxis.html) methods. Yes, it was {ref}`detective work ` all over again! :::{code-block} python :caption: How to modify a plot automatically generated by ROOT from ROOT import TFile, gROOT, TCanvas, gPad myFile = TFile("experiment.root") tree1 = gROOT.FindObject("tree1") my_canvas = TCanvas() tree1.Draw("chi2","","e") # Get the temporary histogram used by TTree::Draw() htemp = gPad.GetPrimitive("htemp") htemp.GetXaxis().SetTitle("chi2") htemp.GetYaxis().SetTitle("number of events") htemp.GetYaxis().SetTitleOffset(1.5) my_canvas.Draw() ::: ::::