! Example with a clipped color gradient. ! Author: Francois Tonneau size 15 8 left = 0.05 right = 0.0804 top = 0.1480 reddish = rgb255(229, 30, 32) blueish = rgb255( 33, 76, 155) greenish = rgb255( 13, 130, 53) set font ss lwidth 0.03 amove 2.5 1.5 ! We plot the data as a series of scatter plots with error lines. begin graph size 10.5 5.5 fullsize xaxis min 0.05 max 0.10 dticks 0.01 nolast format "fix 2" yaxis min 0.00 max 0.20 dticks 0.05 nolast format "fix 2" ticks length 0.15 x2ticks off labels hei 0.45 dist 0.25 ynames "\sethei{0.35}0.00" 0.05 0.10 "\sethei{0.4}{\it H}_{c}" xtitle "{\it L_{0}} (m)" dist 0.30 ytitle "\sethei{0.4}{\it H}\sethei{0.35}(T)" dist 0.35 data "clip-ft.dat" & d1=c1,c2 d2=c1,c3 & d3=c4,c5 d4=c4,c6 & d5=c7,c8 d6=c7,c9 & d7=c10,c11 d8=c10,c12 & d9=c4,c13 d1 marker fsquare color black msize 0.23 d3 marker fcircle color reddish msize 0.25 d5 marker ftriangle color blueish msize 0.26 d7 marker fdiamond color greenish msize 0.32 ! Most of the error lines are vertical ('err'), but we also add horizontal ! error lines ('herr') to dataset d3: d1 err d2 errwidth 0.3 lwidth 0.03 d3 err d4 errwidth 0.3 lwidth 0.03 d5 err d6 errwidth 0.3 lwidth 0.03 d7 err d8 errwidth 0.2 lwidth 0.03 d3 herr d9 herrwidth 0.3 lwidth 0.03 ! Now we draw a colored gradient/region, using a low-rank layer to stay ! behind the data points and the axes: begin layer 300 draw filled_region end layer end graph ! In GLE, gradients/colormaps occupy a rectangular area, whereas we want our ! colored gradient to fill a curved contour. The solution is to use the contour ! as a boundary and clip the gradient after it. This involves four steps: ! ! 1. Begin a clipping block to save GLE's default clipping state, which will be ! restored later. ! ! 2. Write a 'begin path ... end path' block with the 'clip' option on. Until ! the end of the clipping block, anything drawn after the path will remain ! clipped inside it. ! ! 3. Move to what will be the lower left corner of the gradient/colormap, and ! draw the rectangular gradient. Because of step (2), the visible gradient ! will stay inside the clipping path. ! ! 4. End the clipping block, restoring the default clipping state. sub filled_region begin clip amove xg(left) yg(0) set lwidth 0.06 begin path clip stroke aline xg(right) yg(0) aline xg(left) yg(top) curve 88 3 1.4 6.1 closepath end path amove xg(left) yg(0) ! As we know, a colormap associates to each point of a rectangle a ! number f that ranges from 0 to 1 and that depends on the (x, y) ! coordinates of this point. When used with the 'palette' option, ! the colormap command takes the following arguments: ! ! "f(x,y)", a formal expression of x and y ! ! x0 and x1, the initial and final values of x along the x-axis ! ! y0 and y1, the initial and final values of y along the y-ayis ! ! the number of steps for x and the number of steps for y ! ! the width and height of the rectangle in cm ! ! palette 'pal', where 'pal' refers to a subroutine that maps numbers ! in the 0-1 range to colors. ! In our example, we let x and y range from 0 to 1 in 50 steps each. Our ! "f(x,y)" expression is "z(x,y)", in reference to a 'z' subroutine we ! define below, and our palette is 'sky', also defined below. We add a ! small amount of padding to each side of the gradient rectangle to ! make sure that our region is well covered and that no whitespace ! shows through: local padding = 0.1 local x0 = 0 local x1 = 1 local y0 = 0 local y1 = 1 local nx = 50 local ny = 50 local width = xg(right) - xg(left) + padding local height = yg(top) - yg(0) + padding colormap "z(x,y)" x0 x1 y0 y1 nx ny width height palette sky end clip end sub ! Here is the subroutine that assigns a value in the 0-1 range to each point of ! the gradient rectangle. (The name, 'z', is arbitrary; we could have chosen any ! other name, as long as we make reference to it in our colormap command.) The ! returned value is a linear function of the distance from (x, y) to the upper ! left corner of the rectangle, (0, 1): sub z x y local distance = (x - 0)^2 + (y - 1)^2 local maximum = (1 - 0)^2 + (0 - 1)^2 local gain = 0.7 local value = gain * distance/maximum return value end sub ! Finally, our 'sky' palette. A palette is a subroutine that takes a numeric ! argument as input and that returns a valid GLE color. The argument is assumed ! to be in the 0-1 range. In the case of our sky palette, the returned rgb255 ! value is a linear mixture of two colors in standard RGB space: sub sky z local r_cool = 143; local g_cool = 189; local b_cool = 172 local r_warm = 240; local g_warm = 240; local b_warm = 240 local r = z * r_warm + (1 - z) * r_cool local g = z * g_warm + (1 - z) * g_cool local b = z * b_warm + (1 - z) * b_cool return rgb255(r, g, b) end sub ! We finish the figure by adding a legend and two labels: begin key absolute 10.30 4.65 nobox just tl dist 0.5 hei 0.45 marker fsquare color black msize 0.23 text "{\it A}" marker fcircle color reddish msize 0.25 text "\Delta {\it C}" marker ftriangle color blueish msize 0.26 text \alpha marker fdiamond color greenish msize 0.32 text \beta end key set hei 0.6 amove xg(0.078) yg(0.170) write "Phase \raise{-0.06em}{II}" amove xg(0.061) yg(0.055) write "Phase \raise{-0.06em}I" set hei 0.4 amove xg(0.053) yg(0.175) write "{\it L} || \sethei{0.35}d" ! Done. We have learned about clipping and color gradients.