SetLegend — Add text to a legend box




SetLegend sets the text to be displayed in the legend. A legend is often needed when a plot contains more than one data set, to identify the purpose of the different data sets being plotted. The legend text consists of multiple lines, with each line identifying one data set on the plot. PHPlot adds an identifying color box or shape marker next to each line in the legend.



An array with each element containing the text for one line of the legend. Or, if not an array, the one line to be appended to the legend. See notes.


By default, no legend is displayed.

The legend usually needs to contain one line of text for each data set plotted on the graph, in the same order as the data array. You can supply all the legend lines in a single call to SetLegend as an array, or you can build up the legend one line at a time with multiple calls to SetLegend, supplying one line per call (in the same order as the data sets in the data array).

By default, legend text lines are displayed in order from top to bottom in the legend. (See SetLegendReverse to reverse the order.) Each line also has a color box or shape maker with the corresponding color from the data colors array. The colors used in the legend color boxes or shape markers are independent of any custom data color callback (see Section 4.5, “Custom Data Color Selection”).

To cancel a legend (perhaps as part of drawing multiple plots on an image), pass an empty array or NULL as $leg.

To control the legend position on the plot, use SetLegendPixels, SetLegendWorld, or the more general SetLegendPosition. You can control the text and color box or shape marker alignment within the legend using SetLegendStyle.

Use SetLegendUseShapes to select color boxes or shape markers in the legend.


Accepting NULL as a valid argument value was added in PHPlot-5.3.1. Through PHPlot-5.3.0, passing NULL would cause an error. Logo

This version of the manual was produced for the PHPlot Sourceforge project web service site, which requires the logo on each page.

To download a logo-free copy of the manual, see the PHPlot project downloads area.