Auto scale left axis based on currently displayed waves

Function AutoscaleLeft()
    if((stringmatch(AxisList(""),"*bottom*")==0)||(stringmatch(AxisList(""),"*left*")==0))
        print "no left or bottom axis"
    else
        getaxis/q bottom
        variable num=0,minB=V_min,maxB=V_max,minL=inf,maxL=-inf
        do
            if (waveexists(WaveRefIndexed("",num,1)))      
                Duplicate/o WaveRefIndexed("",num,1), temp
                if(wavemax(temp,minB,maxB)>maxL)
                    maxL=wavemax(temp,minB,maxB)
                endif
                if(wavemin(temp,minB,maxB)<minL)
                    minL=wavemin(temp,minB,maxB)
                endif
            else
                break
            endif
            num+=1
        while(1)
        setaxis left, minL,maxL
        killwaves/z temp
    endif
End
Menu "Graph"
    "Autoscale Left Axis",/q ,AutoscaleLeft()
End
Menu "TracePopup"
    "Autoscale Left Axis",/q ,AutoscaleLeft()
End
I see you're autoscaling the Y axis to the Y data visible in the graph's current X range.

You're code is essentially re-implementing:

SetAxis/A=2 left


except that your code "locks" the left axis range to the current Y min/max over the current X range and assumes that all the traces are waveforms (you're using x scaling to select "visible" Y values).

That said, this implementation is a bit faster:
Function SimpleAutoscaleLeft()
    if((stringmatch(AxisList(""),"*bottom*")==0)||(stringmatch(AxisList(""),"*left*")==0))
        print "no left or bottom axis"
    else
        Variable timerRefNum=StartMSTimer
        getaxis/q bottom
        variable num=0,minB=V_min,maxB=V_max,minL=inf,maxL=-inf
        do
            WAVE/Z w= WaveRefIndexed("",num,1)
            if (waveexists(w))     
                WaveStats/Q/M=0/R=(minB,maxB) w // /M=0 is fast, and we do it only once, not 4 calls to wavemax/min
                maxL=max(maxL, V_max)
                minL=min(minL,V_min)
            else
                break
            endif
            num+=1
        while(1)
        Variable microSeconds = stopMSTimer(timerRefNum)
        Print microSeconds/10000, "Simple: microseconds per iteration"
        setaxis left, minL,maxL
    endif
End

--Jim Prouty
Software Engineer, WaveMetrics, Inc.

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More