To plot data in three dimensions, you should use the P2D container. It is rather similar to the P1D, the only difference is that it keeps data in 3D phase space (X,Y,Z). Also, it has less options for drawing and errors for each component are not supported. Below is an example to how draw points in 3D:
>>> from jhplot import * >>> from java.awt import Color >>> >>> c1 = HPlot3D("Canvas",600,400) >>> c1.visible(1) >>> c1.setNameX("X axis") >>> c1.setNameY("Y axis") >>> c1.setRange(-5,10,-5,5,-10,20) # set range >>> >>> h1= P2D("3D data set") >>> h1.setSymbolSize(6) >>> h1.setSymbolColor(Color.blue) >>> h1.add(1.,2.,3.,) # add X,Y,Z >>> h1.add(4.,4.,5.,) # add X,Y,Z >>> c1.draw(h1) # draw in 3D >>> >>> h1= P2D("new 3D data set") >>> h1.setSymbolSize(6) >>> h1.setSymbolColor(Color.red) >>> h1.add(-1.,2.,1.,) # add X,Y,Z >>> h1.add(5.,0.,4.,) # add X,Y,Z >>> c1.draw(h1) # draw again in red
You do not need to specify the "setRange()" method, the range can be set automatically. Look at the example "p2d_points.py".
It should be noted that if you will start rotate the 3D plot, you will notice that some points may overlay another set. I do not have full solution yet to this problem - remember, HPlot3D does not use JAVA3D at all!
To plot extended objects in three dimensions, like lines and cubes, use the P3D container. The construction of this container is similar to P2D. The only difference is that each data point in X,Y,Z, has additional parameter representing the extension of the point in the corresponding direction.
>>> from jhplot import * >>> from java.awt import Color >>> >>> c1 = HPlot3D("Canvas",600,400) >>> c1.visible(1) >>> c1.setNameX("X axis") >>> c1.setNameY("Y axis") >>> c1.setRange(-5,10,-5,5,-10,20) # set range >>> >>> h1= P3D("3D object") >>> h1.setPenColor(Color.blue) >>> h1.add(4.0,1.0,8.0,2.0,3.0,1.0) # build a cube, with X,dX,Y,dY,Z,dZ >>> h1.add(5.0,2.0,3.0,1.0,8.0, 0.0) # make a line long Z >>> c1.draw(h1) # draw in 3D >>> >>> h2= P3D("new 3D objects") >>> h2.setPenColor(Color.red) >>> h2.add(-0.5,3.0,-1.0,2.0,6.0,2.0) # build a cube, with X,dX,Y,dY,Z,dZ >>> c1.draw(h2) # draw again in red
Look at the example "p3d_points.py".
To plot 2D functions and histograms, you should use again the HPlot3D class. Here is a typical example which shows how to plot two functions on the same plot:
>>> from jhplot import HPlot3D >>> from jhplot import F2D >>> c1 = HPlot3D("Canvas",600,400) >>> c1.visible(1) >>> c1.setNameX("X axis") >>> c1.setNameY("Y axis") >>> f1 = F2D("2*exp(-x*y/20)+10*sin(pi*x)/y", -2.0, 5.0, -2.0, 5.0) >>> f2 = F2D("4*x*y", -2.0, 5.0, -2.0, 5.0) >>> c1.draw(f1,f2)
Here, the F2D class is the main class to build a 2D function.
The H2D class was derived from the class Histogram2D of JAIDA. You can plot 2D histograms in the same way as 2D functions using HPlot3D canvas:
>>> from jhplot import HPlot3D >>> from jhplot import H2D >>> from java.util import Random >>> c1 = HPlot3D("Canvas",600,400) >>> c1.visible(1) >>> c1.setNameX("X axis") >>> c1.setNameY("Y axis") >>> h1 = H2D("My 2D Test 1",30,-3.0, 3.0, 30, -3.0, 3.0) >>> rand = Random() >>> for i in range(5000): ... h1.fill(rand.nextGaussian(),rand.nextGaussian()) >>> c1.draw(h1)
By default, histograms are shown with bards. The color style can be changed using "setColorMode(int)" method (0 - WIREFRAME, 1 - HIDDEN, 2 - SPECTRUM IN COLOR, 3 - GRAYSCALE, 4 - DUALSHADES).
The histograms can also be shown using a surface (setSurface() method). In this case, the number of bins in X and Y should be set the same.
You can overlay two 2D histograms on one figure, if they are plotted using the surface option. In addition, you can plot histogram and a function on the same HPlot3 plot. See the example in ``macros/example/histo2D_2h.py'' and ``macros/example/histo2D_2hf.py''.