In addition to data, histograms, functions, HPlot canvas can show arbitrary shapes (boxes, text, images, arrows) in the user (“USER”) coordinates (i.e. given by the axis values) or in the absolute coordinates (“NDC”). You can mix data and shapes in arbitrary order.
The following shapes can be plotted:
You should also remember that you can always draw shapes with data points. Here is an example how to draw an ellipse with semi-major (longest radius) and semi-minor (shortest radius) radii:
Here is a simple code to do this:
1: # Graphics/2D | C | 1.7 | S.Chekanov | Display an ellipse shape using P1D data points 2: 3: from java.awt import * 4: from jhplot import * 5: from jhplot.shapes import * 6: from math import * 7: 8: c1 =HPlot("Canvas",600,600) 9: c1.setGTitle("Drawing shapes") 10: c1.setAntiAlias(1) 11: c1.setNameX("X") 12: c1.setNameY("Y") 13: c1.setRange(-5.0, 5.0, -5, 5.0) 14: c1.visible(1) 15: 16: p1=P1D("Ellipse data") 17: # a, b are the radius on the x and y axes respectively 18: a=3 # major 19: b=2 # minor 20: xshift=1 # (X,Y) position 21: yshift=2 22: step=0.05 # step 23: ra=[v*step for v in range(0,int(2*3.2/step))] # generate points (3.2 instead of 2*pi!) to close the object 24: for t in ra: 25: x = a*cos(t)+xshift 26: y = b*sin(t)+yshift 27: p1.add(x, y) 28: c1.draw(p1) 29: 30: # export to some image (png,eps,pdf,jpeg...) 31: # c1.export(Editor.DocMasterName()+".png");
You can convert it to Groovy or Java code using the same logic. Decrease the step size to obtain a smooth line.
Now let us construct rotated ellipse by some angle and overlay it with a 2D Ellipse using “2D” shape approach:
The code to generate this image is below:
Finally, one can generate random data points following the ellipse shape. We will use parametric description of the elliips, rotate it and generate random numbers:
The Python code this image is below:
Pay attention to this example. In the section Fitting data with shapes we will show how to fit 2D data using shapes, such as eclipse, and determine ellipse characteristics.
Of course, you can use the basic 2D primitives to draw shapes. Here is a simple example how to draw such shapes:
You can find a script that generates this image below. It shows how to add X-Y data, histograms a then draw simple 2D graphic primitives on the top: