The P1D class is a container which keeps information on a data point in (X,Y) together with 1st and 2nd level errors, which are usually used to show statistical and systematical errors in X and Y. This means that one entry of this container is characterized by 10 double-precision numbers. The P1D container can be drawn using the same "draw()" method as any histogram.
>>> from jhplot import HPlot >>> from jhplot import P1D >>> c1=HPlot("Canvas",600,400) >>> c1.visible(1) >>> c1.setAutoRange() >>> c1.setGTitle("Example of symbols", Color.blue) #put title >>> p1= P1D("show points") >>> for i in range(10): .... p1.add(i*2.0,i*10.0) >>> c1.draw(p1)
As before for F1D and H1D classes, the "draw" method can take arrays of F1D functions as argument.
In this case all the statistical errors are set to zero. If you want to plot data points with 2-level error bars, use this method
p1.add(x,y,xLeft,xRight,yUpper,yLower,xLeftSys,xRightSys,yUpperSys,yLowerSys)
where "xLeft,xRight,yUpper,yLower" are the 1st level errors on X and Y, while "xLeftSys,xRightSys,yUpperSys,yLowerSys" are the 2nd level errors on X and Y.
Of course , in many cases, you do not have the full sets of errors. If you do not have any errors, use this constructor:
p1.add(x,y)In this case all errors are set to zero.
In case if you need to specify only symmetrical uncertainties on Y (i.e., for example, statistical errors), then use this method:
p1.add(x,y,error)
where "error" is the statistical error on Y, i.e. "yUpper=yLower". All other errors are set to zero.
If the error on Y is asymmetric, use this method:
p1.add(x,y,error_up, error_down)
where "error_up=yUpper" and "error_down=yLower" are the upper and lower error on Y.
If there are only 1st-level errors, then you can fill P1D as:
p1.add(x,y,xLeft,xRight,yUpper,yLower)
while the 2nd level errors are set to zero.
Here are several important methods associated with P1D:
>>> p1.setStyle("p") # set style ``p''- symbols, ``l'' - lines >>> p1.setColor(Color.red) # sets color >>> p1.setSymbolSize(int w) # sets the symbol size >>> p1.setSymbol(int w) # sets the symbol type
You can edit the plot using a pop-up menu ``Edit'' set all the attribute using the style editor.
Look at an example located in ``macros/examples/points1.py''.
There are many methods which go together with the P1D data holder to display error bars, assuming the error values have been filled To display errors, set
>>> p1.setErr(true) # set true for 1st level errors >>> p1.setErrSys(true) # set true for 2nd level errors
There are two separate methods to control horizontal and vertical error bars:
>>> p1.setErrX(boolean) # set true or 1 (jython) >>> p1.setErrY(boolean) >>> p1.setErrColorX(Color color) # indicate color used for X error bars >>> p1.setErrColorY(Color color) # indicate color used for Y error bars >>> p1.setPenWidthErr(int w) # pen width for 1st level errors >>> p1.setPenWidthErrSys(int w) # pen width for 2nd level errors
To control 2nd-level errors, use:
>>> p1.setEerrSysX(boolean) # set true or 1 (jython) >>> p1.setEerrSysY(boolean)
One can draw a filled area which spans 1st level error bars (i.e. statistical errors) with the following statements:
>>> p1.setErrFill(boolean) # fill or nor the area >>> p1.setErrFillColor(Color color) # fill color >>> p1.setErrFillColor(Color color, double trans) # same + transparency level
Here "color" is the color used to fill the area and "trans" is the transparency
level. For example, "p1.fillErrorsColor(Color.green,0.5)" will fill
green area with transparency. To fill
To fill area which spans the 2nd level error bars use:
>>> p1.setErrSysFill(boolean) # fill or not 2nd level errors >>> p1.setErrSysFillColor(Color color) # fill color >>> p1.setErrSysColor(Color color, double trans) # same + transparency
The HPlot canvas can be used to display a P1D data in a form of a contour plot. To do this, use the method "setContour(true)" of the HPlot class.
>>> c1.setContour(boolean) # sets or not a contor style to HPlot >>> c1.setContourLevels(n) # n - number of color levels >>> c1.setContourBins(nX,nY) # number of bins in X and Y >>> c1.setContourBar(boolean) # set or not a color line >>> c1.setContourGray(boolean) # set or not white-black style
You can find an example in "contour.py" file in the "example" directory.
It should be noted that it is also possible to use the HPlot3D class to show data in 3D as well as in a contor type of plots.
You can initiate P1D using data from an external file:
>>> from jhplot import HPlot >>> from jhplot import P1D >>> c1=HPlot("Canvas",600,400) >>> c1.visible(1) >>> c1.setAutoRange() >>> p1=P1D("show points", "data.d") >>> c1.draw(p1)
where "data.d" is a file with data points. The file can contain statistical and systematical errors. As you see, unlike many graphical packages, you need only a few lines to create a plot from the file with the name "data.d"! Please look at the example "example/points2.py".
One can construct a P1D from a H1D histogram as:
>>> p1.P1D("New name",h1) # convert a histogram to P1D, or >>> p1.P1D(h1) # convert a histogram to P1D, keep the same title.
It should be noted that X values are given by the weighted mean in each histogram bin (not by the center of the bin). The values on Y are the sum of the weights of the histogram. The errors on X, as well as all 2nd level errors on X and Y are set to zero.
You can write a file with the P1D data as:
>>> p1=P1D("show points", "data.d") >>> p1.toFile("newfile.d")
where "newfile.d" is a name of a file.
One can also export the data to a LaTeX table as
>>> format=DecimalFormat("##.####E00") >>> p4.toFileAsLatex("Output.tex",xformat,xformat)
You should specify an appropriate format for the numbers in the LaTeX table
You can print a P1D container on the Linux console as
>>> p1.print()
In some cases, it is convenient to show the data as a table in a separate frame, so one can sort and search for a particular value. In this case, use
>>> p1.toTable()
This method calls to the class HTable which is discussed in Section :autorefsection21. Analogously, the data can be exported to a spreadsheet which is also discussed in Section :autorefsection21.
In a program, you can access P1D values as
>>> p1=P1D("show points", "data.d") >>> p1.size() # size of the data >>> p1.clear() # clear the P1D >>> p1.getMin(int) # min value for axis=0,1,.. >>> p1.getMax(int) # max value for axis=0,1,.. >>> p1.mean() # mean value >>> p1.setTitle(String) # set a new title >>> p1.getTitle(String) # get a new title >>> p1.getX(i) # x value at position i >>> p1.getY(i) # y value at position i >>> p1.getXleft(i) # left error on x at position i >>> p1.getXright(i) # right error on x at position i >>> p1.getXleftSys(i) # left 2nd-level error on x at position i >>> p1.getXrightSys(i) # right 2nd-level error on x at position i >>> p1.getYupper(i) # upper error on y at position i >>> p1.getYlower(i) # lower error on y at position i >>> p1.getYupperSys(i) # upper 2nd-level error on y at position i >>> p1.getYlowerSys(i) # lowert 2nd-level error on y at position i
The 2nd-level error is usually used to show systematical uncertainty on the data point. Except for "size()", all the methods return double precision numbers. Use Jython statement "type" to find out which type of values they return.
If you have two P1D containers, one can do the following operations:
>>> p1=P1D("first", "data1.d") >>> p2=P1D("second", "data2.d") >>> p3=p1.merge(p2) # merge 2 containers into p3 >>> p3=p1.oper(p2,"New Title","+") # add p1 and p2 >>> p3=p1.oper(p2,"New Title","-") # subtract p2 from p1 >>> p3=p1.oper(p2,"New Title","*") # multiply p1 by p2 >>> p3=p1.oper(p2,"New Title","/") # divide p1 by p2
One can skip the string with a new title if you want to keep the same title as for the original P1D. For example, in this case, the additive operation will be ``p3=p1.oper(p2,"+")'' It should be noted that errors on p3 will be propagated assuming that all uncertainties associated with p1 and p2 are independent (for 1st and 2nd levels). All graphical attributes are preserved during the manipulations.
To scale P1D, use a similar statement:
>>> p3=p1.oper("New Title", scaleFactor )
where ``scaleFactor'' is double or integer number. The title string is optional. The scale factor only scales values in Y and associated uncertainties on Y (i.e. 1st and 2nd levels).
The operations above assume that there are no correlations between the P1D data holders. However, you can also specify the correlation coefficients. Read the jHPlot API for more details. Below is just a simple example illustrating it:
# fill data set 1 points with 2 points >>> p1= P1D("data1") # use only statistical errors on Y >>> p1.add(10,100,5,5) >>> p1.add(20,50,5,5) # fill data set 2 with 2 points >>> p2= P1D("data2") # use only statistical errors on Y >>> p2.add(10,40,5,5) >>> p2.add(20,40,5,5) # add with 50% correlations # build a data holder with correlation coefficient >>> corr=P1D("correlation coefficients") >>> corr.add(0,0,0.5,0.5) >>> corr.add(0,0,0.5,0.5) # add them. Do not do anything with X >>> p3=p1.oper(p2,"added with 50% corr.","+","Y",corr)
One can also transform a P1D data holder using some function with the error propagation for either "X" or "Y" component or both. You can do it as:
>>> p1=p1.move("function", "axis" )where "function" is "exp", "log", "sqrt", "cos", "sin" etc. (see the API for more details). Axis is "X" (move only X values), "Y" (move only Y values), or "XY" (move both). For example:
>>> p1=p1.move("log", "Y" )
will transform all "Y" values (including the errors associated with them) to log(Y).
One can also calculate a weighted average from several P1D data containers using this method:
>>> p1=p1.addAndAverage(P1D[])
This method adds an array of P1D to the original P1D class and returns weighted average based on statistical errors on Y (i.e. 1st-level errors).
Using the P1D class, it is easy to evaluate systematical using only a few lines of your code. If you have several measurements, and each measurement is represented by a P1D data holder, one can get P1D representing the final measurements using the method "getSys()", which returns a P1D object with systematical uncertainties.
>>> p0= P1D("default") >>> pp=[] >>> p1= P1D("data1") >>> pp.append(p1) >>> p2= P1D("data2") >>> pp.append(p2) >>> p3= P1D("data3") >>> pp.append(p3) >>> .... >>> psys=p0.getSys(pp) # now "psys" includes syst. uncertainties >>> psys.setErr(1) >>> c1.draw(psys)
It should be noted that systematical uncertainties are added in quadrature (i.e. it is assumed that they are independent of each other).