Your attachment just shows some numbers and a unit, I guess? It's a bit difficult to understand what you want to do. Can you give some more details of your problem.
Use the drawing tools to draw a line approximately where you want, then double-click on the line to bring up the dialog for settings and change the coordinate system from the default plot relative to axis bottom for the X axis or axis left for the Y axis. Then you can edit the values to be precisely what you want them to be.
As an example, an X-scale bar of 0.2 units would look like this
SetDrawLayer UserFront SetDrawEnv xcoord= bottom,ycoord= prel // X coordinate is taken from bottom axis DrawLine0.2,0.802547770700637,0.4,0.802547770700637// the .2 and .4 are start and end of line, in axis coordinates DrawText0.233552631578948,0.78343949044586,".2 s"// 0.4 -0.2 = 0.2 of whatever units your data are scaled in
I once made a graph hook function to draw out a marquee, truncate the width to an even value and draw and label the scale bar where the marquee was.
Here it is. It does both X and Y, as in your example. I had it draw the scale bar in white, cause I was placing it on images with dark background. But I just modified it to use constants for colour. Here it is red. Change all values to 0 to draw in black.
It draws in the programmer front drawing layer. If you do it multiple times, it will draw multiple scale bars. If you hold down the shift key while running it, it will clear all drawing in the programmer front layer before drawing the new scale bar.
It tries to read units from the axes, so set units for data scaling and x scaling.
make/o test = {0,1}
•setscale/Px0,1,"s" test
•setscale d 0,0, "V" test
•Display/W=(35,44,467,306) test
I think it may only work with left and bottom axes, not top and right, or other, user-defined axes.
July 10, 2014 at 07:13 pm - Permalink
As an example, an X-scale bar of 0.2 units would look like this
SetDrawEnv xcoord= bottom,ycoord= prel // X coordinate is taken from bottom axis
DrawLine 0.2,0.802547770700637,0.4,0.802547770700637 // the .2 and .4 are start and end of line, in axis coordinates
DrawText 0.233552631578948,0.78343949044586,".2 s" // 0.4 -0.2 = 0.2 of whatever units your data are scaled in
I once made a graph hook function to draw out a marquee, truncate the width to an even value and draw and label the scale bar where the marquee was.
Here it is. It does both X and Y, as in your example. I had it draw the scale bar in white, cause I was placing it on images with dark background. But I just modified it to use constants for colour. Here it is red. Change all values to 0 to draw in black.
It draws in the programmer front drawing layer. If you do it multiple times, it will draw multiple scale bars. If you hold down the shift key while running it, it will clear all drawing in the programmer front layer before drawing the new scale bar.
It tries to read units from the axes, so set units for data scaling and x scaling.
•setscale /P x 0,1,"s" test
•setscale d 0,0, "V" test
•Display /W=(35,44,467,306) test
I think it may only work with left and bottom axes, not top and right, or other, user-defined axes.
STATIC CONSTANT kSCALBARg = 0
STATIC CONSTANT kSCALBARb = 0
Function DrawScaleBar():GraphMarquee
//Get the marquee coordinates and calculate xsize as distance between left and right
string vAxis = "left", hAxis = "bottom"
string axes = axislist ("")
if ((whichlistItem ("left", axes, ";")) == -1)
if ((whichlistItem ("right", axes, ";")) == -1)
doAlert 0, "Neither left nor right vertical axes were found."
else
vAxis = "right"
endif
endif
if ((whichlistItem ("bottom", axes, ";")) == -1)
if ((whichlistItem ("top", axes, ";")) == -1)
doAlert 0, "Neither top nor bottom horizontal axes were found."
else
hAxis = "top"
endif
endif
string leftAxisUnits = stringByKey ("UNITS", AxisInfo("", vAxis), ":", ";")
string bottomAxisUnits = stringByKey ("UNITS", AxisInfo("", hAxis), ":", ";")
//Get the marquee coordinates and calculate xsize as distance between left and right
GetMarquee/K $vAxis, $hAxis
variable xSize = abs ((V_right - V_left))
//Chop xSize to a nice round number to draw a scalebar
if ((xSize < 2e06) && (xSize > 1e06))
xSize = 1e06
elseif (xSize > 5e05)
xSize = 5e05
elseif (xSize > 2e05)
xSize = 2e05
elseif (xSize > 1e05)
xSize = 1e05
elseif (xSize > 5e04)
xSize = 5e04
elseif (xSize > 2e04)
xSize = 2e04
elseif (xSize > 1e04)
xSize = 1e04
elseif (xSize > 5e03)
xSize = 5e03
elseif (xSize > 2e03)
xSize = 2e03
elseif (xSize > 1e03)
xSize = 1e03
elseif (xSize > 5e02)
xSize = 5e02
elseif (xSize > 2e02)
xSize = 2e02
elseif (xSize > 1e02)
xSize = 1e02
elseif (xSize > 5e01)
xSize = 5e01
elseif (xSize > 2e01)
xSize = 2e01
elseif (xSize > 1e01)
xSize = 1e01
elseif (xSize > 5)
xSize = 5
elseif (xSize > 2)
xSize = 2
elseif (xSize > 1)
xSize = 1
elseif (xSize > 5e-01)
xSize = 5e-01
elseif (xSize > 2e-01)
xSize = 2e-01
elseif (xSize > 1e-01)
xSize = 1e-01
elseif (xSize > 5e-02)
xSize = 5e-02
elseif (xSize > 2e-02)
xSize = 2e-02
elseif (xSize > 1e-02)
xSize = 1e-02
elseif (xSize > 5e-03)
xSize = 5e-03
elseif (xSize > 2e-03)
xSize = 2e-03
elseif (xSize > 1e-03)
xSize = 1e-03
elseif (xSize > 5e-04)
xSize = 5e-04
elseif (xSize > 2e-04)
xSize = 2e-01
elseif (xSize > 1e-04)
xSize = 1e-04
elseif (xSize > 5e-05)
xSize = 5e-05
elseif (xSize > 2e-05)
xSize = 2e-05
elseif (xSize > 1e-05)
xSize = 1e-05
elseif (xSize > 5e-06)
xSize = 5e-06
elseif (xSize > 2e-06)
xSize = 2e-06
elseif (xSize > 1e-06)
xSize = 1e-06
elseif (xSize > 5e-07)
xSize = 5e-06
elseif (xSize > 2e-07)
xSize = 2e-06
elseif (xSize > 1e-07)
xSize = 1e-07
elseif (xSize > 5e-08)
xSize = 5e-08
elseif (xSize > 2e-08)
xSize = 2e-08
elseif (xSize > 1e-08)
xSize = 1e-08
elseif (xSize > 5e-09)
xSize = 5e-09
elseif (xSize > 2e-09)
xSize = 2e-09
elseif (xSize > 1e-09)
xSize = 1e-09
elseif (xSize > 5e-10)
xSize = 5e-10
elseif (xSize > 2e-10)
xSize = 2e-10
elseif (xSize > 1e-10)
xSize = 1e-10
endif
//The average y-position of the selected area will be horizontal position of scalebar
variable yPos = (V_bottom + V_top)/2
//Draw the scalebar
if (getkeyState (0) & 4)
SetDrawLayer/K ProgFront // using /K kills any old drawing (like previous scalebar) that might be lying around
else
SetDrawLayer ProgFront
endif
SetDrawEnv xcoord=$hAxis, ycoord=$Vaxis // need to use graph axis coordinates
SetDrawEnv linethick=5
SetDrawEnv linefgc= (kSCALBARr,kSCALBARg,kSCALBARb) // color = white
DrawLine V_left, yPos, (V_left + xSize), yPos
// print scalebar length a little bit above the scale bar, so add a return on the end and middle align text for Y
// center adjust text for X to position in center of scale bar
string valueStr
sprintf valueStr "%.0W1P%s\r", xSize, bottomAxisUnits
SetDrawEnv textrgb= (kSCALBARr,kSCALBARg,kSCALBARb),textxjust = 1, textyjust=1, xcoord=$hAxis, ycoord=$vAxis,fstyle=1
DrawText V_left + (xSize/2),yPos,valueStr
// If left and bottom axes are in different units, draw a scalebar for left axis as well
if (cmpStr (leftAxisUnits, bottomAxisUnits) != 0)
variable ySize = abs ((V_bottom - V_top))
variable xPos = (V_left + V_right)/2
//Chop ySize to a nice round number to draw a scalebar
if ((ySize < 2e06) && (ySize > 1e06))
ySize = 1e06
elseif (ySize > 5e05)
ySize = 5e05
elseif (ySize > 2e05)
ySize = 2e05
elseif (ySize > 1e05)
ySize = 1e05
elseif (ySize > 5e04)
ySize = 5e04
elseif (ySize > 2e04)
ySize = 2e04
elseif (ySize > 1e04)
ySize = 1e04
elseif (ySize > 5e03)
ySize = 5e03
elseif (ySize > 2e03)
ySize = 2e03
elseif (ySize > 1e03)
ySize = 1e03
elseif (ySize > 5e02)
ySize = 5e02
elseif (ySize > 2e02)
ySize = 2e02
elseif (ySize > 1e02)
ySize = 1e02
elseif (ySize > 5e01)
ySize = 5e01
elseif (ySize > 2e01)
ySize = 2e01
elseif (ySize > 1e01)
ySize = 1e01
elseif (ySize > 5)
ySize = 5
elseif (ySize > 2)
ySize = 2
elseif (ySize > 1)
ySize = 1
elseif (ySize > 5e-01)
ySize = 5e-01
elseif (ySize > 2e-01)
ySize = 2e-01
elseif (ySize > 1e-01)
ySize = 1e-01
elseif (ySize > 5e-02)
ySize = 5e-02
elseif (ySize > 2e-02)
ySize = 2e-02
elseif (ySize > 1e-02)
ySize = 1e-02
elseif (ySize > 5e-03)
ySize = 5e-03
elseif (ySize > 2e-03)
ySize = 2e-03
elseif (ySize > 1e-03)
ySize = 1e-03
elseif (ySize > 5e-04)
ySize = 5e-04
elseif (ySize > 2e-04)
ySize = 2e-01
elseif (ySize > 1e-04)
ySize = 1e-04
elseif (ySize > 5e-05)
ySize = 5e-05
elseif (ySize > 2e-05)
ySize = 2e-05
elseif (ySize > 1e-05)
ySize = 1e-05
elseif (ySize > 5e-06)
ySize = 5e-06
elseif (ySize > 2e-06)
ySize = 2e-06
elseif (ySize > 1e-06)
ySize = 1e-06
elseif (ySize > 5e-07)
ySize = 5e-06
elseif (ySize > 2e-07)
ySize = 2e-06
elseif (ySize > 1e-07)
ySize = 1e-07
elseif (ySize > 5e-08)
ySize = 5e-08
elseif (ySize > 2e-08)
ySize = 2e-08
elseif (ySize > 1e-08)
ySize = 1e-08
elseif (ySize > 5e-09)
ySize = 5e-09
elseif (ySize > 2e-09)
ySize = 2e-09
elseif (ySize > 1e-09)
ySize = 1e-09
elseif (ySize > 5e-10)
ySize = 5e-10
elseif (ySize > 2e-10)
ySize = 2e-10
elseif (ySize > 1e-10)
ySize = 1e-10
endif
//Draw the scalebar
SetDrawLayer ProgFront
SetDrawEnv xcoord=$hAxis, ycoord=$vAxis // need to use graph axis coordinates (this will fail if data are plotted on other axes than bottom and left)
SetDrawEnv linethick=5
SetDrawEnv linefgc= (kSCALBARr,kSCALBARg,kSCALBARb) // color = white
DrawLine V_left, yPos, V_left, (yPos + ySize)
// draw label
sprintf valueStr "%.0W1P%s\r", ySize, leftAxisUnits
SetDrawEnv textrgb= (kSCALBARr,kSCALBARg,kSCALBARb),textxjust = 1, textyjust=1, textrot=90, xcoord=$hAxis, ycoord=$vAxis,fstyle=1
DrawText V_left ,yPos + (ySize/2),valueStr
SetDrawLayer UserFront
endif
end
jamie
July 11, 2014 at 11:39 am - Permalink