location conversion: x,y axis values to plot points

This snippet is intended mostly as a Drawing utility, but may have other uses. In an existing Graph, it converts user input in terms of x- and y-axis values to an (x,y) location in plot points. Plot points run from (0,0) at (top of the left vertical axis, left of the bottom horizontal axis) to their maximum values at the opposite lower diagonal. This mode (used in absolute scaling) is useful when creating drawing objects or groups that maintain their size and shape, even under graph re-sizing. The complication is that finding the point values to specify the drawing object location is not obvious. To avoid manual calculation or a trial-and-error method, this snippet converts an easily observed location based on existing axes to a location in plot points.
function info(GraphName,Vx, Vy)  // convert an x,y value in graph axis units
    string GraphName                //  to plot region point values
    variable Vx, Vy

    GetWindow $GraphName  gsize  // inside of graph window
    variable x0=V_left,   x1 = V_right, y0 = V_top, y1 = V_bottom

    GetWindow $GraphName  psize  //  plot region of graph
    variable x2 = V_left, x3 = V_right, y2 = V_top, y3 = V_bottom

    GetAxis/Q /W=$GraphName left  //  left axis range
    variable VB = v_min, VT = v_max

    GetAxis/Q /W=$GraphName bottom //  bottom axis range
    variable VL = v_min, VR = v_max
   
    variable Vpx = ((Vx-VL)/(VR-VL))*(x3-x2) + (x2-x0)  //  x (points) right from bottom axis min
    variable Vpy = ((VT-Vy)/(VT-VB))*(y3-y2) + (y2-y0)  //  y (points) down from left axis max
    Make/O/N=2 W_Vpoint = {Vpx, Vpy}  // globally accessible result wave
end

Caution: tested on Windows 7 only

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More