3.4.2 The arrow and line Commands

Arrows may also be added to multiplot canvases using the arrow command, which has syntax:

arrow from x,y to x,y

The arrow command may be followed by the with keyword to specify to style of the arrow. The line type, line width and colour of the arrow, may be specified using the same syntax as used in the plot command, using the linetype, linewidth and colour modifiers after the word with, as in the example:

arrow from 0,0 to 10,10 \
with linetype 2 linewidth 5 colour red

The style of the arrow may also be specified after the word with, and three options are available: head (the default), nohead, which produces line segments with no arrowheads on them, and twoway, which produces bidirectional arrows with heads on both ends.

The arrow command has a twin, the line command, which has the same syntax but with a different style setting of nohead.

A simple notice generated with the text and arrow commands.

In this example script, we use PyXPlot’s arrow and text commands to produce a simple notice advertising that a lecture has moved to a different seminar room:

# Turn on multiplot mode
set multiplot ; set nodisplay

# Set the dimensions of the notice
w = 20        # Width of notice / cm
h = w/sqrt(2) # Height of notice / cm

# Put a rectangular box around the notice
line from 0,0 to w,0 with linewidth 5
line from w,0 to w,h with linewidth 5
line from w,h to 0,h with linewidth 5
line from 0,h to 0,0 with linewidth 5

# Write the text of the notice in big letters
set texthalign centre ; set fontsize 3
text "$\backslash $bf Astrophysical Fluids Lecture" at w/2,3/4*h
text "$\backslash $bf MOVED to Seminar Room 3" at w/2, h/2
arrow from w/4, h/4 to 3/4*w, h/4 with linewidth 8

# Display the notice
set display ; refresh

The resulting notice is shown below:

\includegraphics[width=\textwidth ]{examples/eps/ex_notice}

A diagram from Euclid’s Elements.

In this more extended example script, we use PyXPlot’s arrow and text commands to reproduce a diagram illustrating the 47th Proposition from Euclid’s First Book of Elements, better known as Pythagoras’ Theorem. A full text of the proof which accompanies this diagram can be found at http://www.gutenberg.org/etext/21076.

set multiplot ; set nodisplay

# Lengths of three sides of triangle
AB = 2*unit(cm)
AC = 4*unit(cm)
BC = hypot(AC, AB) # Hypotenuse
CBA = atan2(AC, AB) # Angle CBA

# Positions of three corners of triangle
Bx = 0*unit(cm)       ; By = 0*unit(cm) # The origin
Cx = Bx + BC          ; Cy = By
Ax = Bx + AB*cos(CBA) ; Ay = By + AB*sin(CBA)

# Positions of constructed points
Dx = Bx               ; Dy = -BC
Lx = Ax               ; Ly = Dy
Ex = Cx               ; Ey = Dy

Hx = Bx + (AB + AC) * cos(CBA)
Hy = By + (AB + AC) * sin(CBA)
Kx = Cx + (     AC) * cos(CBA)
Ky = Cy + (     AC) * sin(CBA)

Fx = Bx + AB*cos(CBA+90*unit(deg))
Fy = By + AB*sin(CBA+90*unit(deg))
Gx = Ax + AB*cos(CBA+90*unit(deg))
Gy = Ay + AB*sin(CBA+90*unit(deg))

# Construct diagram
box from Dx,Dy to Cx,Cy with fillcol grey80
box at Ax,Ay width AC height AC rot CBA-90*unit(deg) with fillcol grey80
box at Bx,By width AB height AB rot CBA with fillcol grey80
line from Bx,By to Kx,Ky
line from Fx,Fy to Cx,Cy
line from Ax,Ay to Dx,Dy
line from Ax,Ay to Lx,Ly
line from Ax,Ay to Ex,Ey

# Label diagram
set fontsize 1.3
TG = 0.5*unit(mm) # Gap left between labels and figure
text "A" at Ax,Ay gap TG*5 hal c val b
text "B" at Bx,By gap TG   hal r val t
text "C" at Cx,Cy gap TG   hal l val t
text "D" at Dx,Dy gap TG   hal c val t
text "E" at Ex,Ey gap TG   hal c val t
text "F" at Fx,Fy gap TG   hal r val c
text "G" at Gx,Gy gap TG   hal c val b
text "H" at Hx,Hy gap TG   hal c val b
text "K" at Kx,Ky gap TG   hal l val c
text "L" at Lx,Ly gap TG   hal c val t

# Display diagram
set display ; refresh

The resulting diagram is shown below:

\includegraphics[width=8cm]{examples/eps/ex_euclid_I_47}

A diagram of the conductivity of nanotubes.

In this example we produce a diagram of the irreducible wedge of possible carbon nanotube configurations, highlighting those configurations which are electrically conductive. We use PyXPlot’s loop constructs to automate the production of the hexagonal grid which forms the basis of the diagram.

BASIS_ANGLE_X = (0 )*unit(deg)
BASIS_ANGLE_Y = (120)*unit(deg)
LINELEN = unit(5*mm)

subroutine line(x1,y1,x2,y2,lw)
{
line from (x1*sin(BASIS_ANGLE_X)+y1*sin(BASIS_ANGLE_Y))*LINELEN, $\backslash $
(x1*cos(BASIS_ANGLE_X)+y1*cos(BASIS_ANGLE_Y))*LINELEN $\backslash $
to (x2*sin(BASIS_ANGLE_X)+y2*sin(BASIS_ANGLE_Y))*LINELEN, $\backslash $
(x2*cos(BASIS_ANGLE_X)+y2*cos(BASIS_ANGLE_Y))*LINELEN $\backslash $
with linewidth lw
}

subroutine hexagon(x,y,lw)
{
call line(x ,y ,x ,y-1,lw)
call line(x ,y-1,x+1,y-1,lw)
call line(x+1,y-1,x+2,y ,lw)
call line(x+2,y ,x+2,y+1,lw)
call line(x+2,y+1,x+1,y+1,lw)
call line(x+1,y+1,x ,y ,lw)
}

set multiplot
set nodisplay

for XPOS=0 to 10
{
for YPOS=0 to XPOS+1
{
x = 1*XPOS + 2*YPOS
y = 2*XPOS + 1*YPOS
call hexagon(x,y, conditionalN((XPOS-YPOS)%3==0,4,1))
text ’%d,%d’%(XPOS,YPOS) $\backslash $
at ((x+1)*sin(BASIS_ANGLE_X)+y*sin(BASIS_ANGLE_Y))*LINELEN, $\backslash $
((x+1)*cos(BASIS_ANGLE_X)+y*cos(BASIS_ANGLE_Y))*LINELEN $\backslash $
hal cen val cen
}
}

set display
refresh

\includegraphics[width=9cm]{examples/eps/ex_nanotubes}