Drawings

ctioga2 has a series of functions to draw elements which are not data points in themselves, but to help understand and read data.

Basic drawings

Let’s first annotate a gaussian curve with a line and some text:

math /xrange=-3:3
margin 0.03
plot exp(-x**2)
l = $(eval 'sqrt(log(2.0))')
draw-line -$(l),0.5 $(l),0.5 /line-style Dashes
draw-text 0,0.3 'Half height width: $w = \sqrt{\ln 2}$' /text-width=3cm 

Note how we used the eval function to compute the value of the half-height width.

Tangents

ctioga2 features a very simple way to draw tangents on a curve, using the draw-tangent command:

math /xrange=-3:3
margin 0.03
plot x**2
draw-tangent 0.3
draw-tangent 0.7 /xto 2 /color black
draw-tangent 0.1 /yextent 2 /color blue

In the first form, without options, draw-tangent only draws an arrow head (in real, a marker) along the curve at the position asked (here, 0.3, which means “at 30 %”). In the second form, we ask a full line that will extend until x = 2. Of course, you can use also /xfrom, /yto and so on. In the last form, one says how long the arrow is in y units. Beware of the sign, though: in this case, as the slope is negative, asking for a positive /yextent makes it go backwards.

Images

Starting from ctioga2 version 0.10, it is possible to include JPEG or PNG images (there are some restrictions on the type of PNG/JPEG images that can be handled), using the draw-image command. We’ll use imagemagick’s rose for the demonstration:

math /xrange=-3:3
margin 0.03
plot sin(x**2)
draw-image rose.jpg -2.5,-0.3 2.5,-0.7 /transparency=0.4
draw-image rose.jpg -2.5,0.9 2.5,0.5 /aspect-ratio=contract

To include a file, just specify the image file, the top-left corner and the bottom right corners of the image. By default, ctioga2 just follows your instructions for the corners, which will probably result in the image’s aspect ratio not being respected. If you care, use either /aspect-ratio=contract or /aspect-ratio=expand to preserve the aspect ratio by respectively not exceeding the original rectangle in the first case and not being smaller than it in the second one.

Latest news

ctioga2 version 0.14.1 is out

Release 0.14.1 of ctioga2 fixes a crash at startup with Ruby 2.3