GetDeviceXY — Translate world coordinates into device coordinates


list($x, $y) = $plot->GetDeviceXY($x_world, $y_world)


GetDeviceXY translates values in world coordinates into values in device coordinates. This is useful if you want to annotate a plot with text or graphics positioned relative to specific data values. Given the coordinates of a point in the coordinate space of your data values, this function returns the pixel coordinates of that point in the image.



The X coordinate to translate from world coordinates.


The Y coordinate to translate from world coordinates.

Return Value

Returns an array of two values ($x, $y) in device coordinates which correspond to the world coordinate parameters.


This function only works after scaling factors have been established, which happens in DrawGraph. So it can only be used in two cases:

GetDeviceXY() will fail with an error message if it is called before scaling is set up.

If the world coordinates represent a point that is not visible on the plot, the returned device coordinates will be outside the plot area, or even outside the image area.

To see how this can be used in callbacks, see Section 4.4.5, “Using Callbacks to Annotate Plots”.

Because there are no valid world coordinates for pie charts, GetDeviceXY() does not work with pie charts.


Starting with PHPlot-5.6.0, this function will fail with pie charts, because they do not have valid world coordinates. Through PHPlot-5.5.0, this function returned somewhat meaningless values when used with pie charts.

This function was added in PHPlot-5.1.0. 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.