Credits | Overview | Plotting Styles | Commands | Terminals |
---|
The fact that marks are deformable means that a single mark definition can be used as a template to draw appropriately scaled marks as mark-up elements to annotate plot ranges or groups of plot elements. This example show definition of a single mark that will be positioned and stretched horizontally to highlight and label selected groups within a bar chart. This example is a simplified version of mark_grouping.dem In the full demo the left-most x value and horizontal extent for each group are calculated from an input data set. Here we assume these values have been pre-calculated and stored in $markup.
It is convenient to dissociate the annotation markup from the specific yrange of the data by plotting the marks and labels against the y2 axis rather than against the y axis. This is not necessary, however. An alternative would be to plot the marks against the y axis but add the keywords "noclip noautoscale" so that the marks neither contribute to the y axis range nor are they clipped against it.
$Group_mark << EOD # x y 1=stroke 0 -0.5 1 0 0 1 1 0 1 1 -0.5 1 0.5 0.0 1 0.5 0.5 1 EOD
set mark 1 $Group_mark
$markup << EOD # label width left_edge "Group 1" 4 1 "Group 2" 3 6 "Group 3" 4 10 "Group 4" 2 15 EOD TOP = 9 # y value of the grouping marks
set link y2 set ytics nomirror rangelimited set border 3
plot $bar_data using ($0+$3):2:(0.8):3:xtic(1) with boxes lc variable, \ $markup using ($3-0.5):(TOP):2:(1) axes x1y2 with marks mt 1 units xy lt -1 lw 1, \ $markup using ($3-0.5+$2/2):(TOP):1 axes x1y2 with labels center offset 0,1.7
A complementary example of using a vertically displaced and stretched mark for annotation is given in mark_labels.dem