5.36. Example - Legend Positioning
Prev | Chapter 5. PHPlot Examples | Next

## 5.36. Example - Legend Positioning

Here are some examples showing the usage of SetLegendPosition to position the legend on the plot. The first two arguments ($x, $y) indicate a point on the legend box, relative to the legend box size, with (0,0) being the upper left corner, and (1,1) being the lower right corner. The third argument $relative_to indicates the positioning mode: image, plot, world, or title. The next two arguments ($x_base, $y_base), along with the positioning mode, indicate where to place the legend point given in the first two arguments. The last two optional arguments ($x_offset, $y_offset) are an additional pixel offset.

Example 5.36. Legend Positioning

Case 1. Place upper left corner of legend at offset (5,5) from upper left corner of image:

    $plot->SetLegendPosition(0, 0, 'image', 0, 0, 5, 5);

Case 2. Place bottom left corner of legend at offset (7,-7) from bottom left corner of image:

    $plot->SetLegendPosition(0, 1, 'image', 0, 1, 7, -7);

Case 3. Place top right corner of legend at top center of plot area:

    $plot->SetLegendPosition(1, 0, 'plot', 0.5, 0);

Case 4. Center the legend in the upper half of the plot area:

    $plot->SetLegendPosition(0.5, 0.5, 'plot', 0.5, 0.25);

Case 5. Place center of legend at world coordinates (2,60):

    $plot->SetLegendPosition(0.5, 0.5, 'world', 2, 60);

Case 6. Place top right corner of legend at offset (-5,5) from world coordinates (4,0):

    $plot->SetLegendPosition(1, 0, 'world', 4, 0, -5, 5);

Case 7. Center the top of the legend below the bottom of the title:

    $plot->SetLegendPosition(0.5, 0, 'title', 0.5, 1);

Prev | Up | Next
5.35. Example - Legend with Shape Markers | Home | 5.37. Example - Setting a Y Tick Anchor