GetDeviceXY

GetDeviceXY — Translate world coordinates into device coordinates

Synopsis

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

Description

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.

Parameters

$x_world

The X coordinate to translate from world coordinates.

$y_world

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.

Notes

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

  • From a drawing callback (see Chapter 6, Callbacks) - that is, a callback whose name starts with 'draw'.

  • If SetPrintImage(False) is used to disable automatic output of the image file, then GetDeviceXY() can be used after DrawGraph returns.

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 6.5, “Using Callbacks to Annotate Plots”.

History

This function was added in PHPlot-5.1.0.