Description This subroutine specifies an explicit range for the y-axis of a user created 2D plot.
Syntax SetUser2DPlotYLimits( plotid, ymin, ymax )
Parameters plotid As Long Identification number of the user 2D chart whose Y-axis limits are being set.
ymin As Double Minimum value along the Y axis. Should be less than ymax.
ymax As Double Maximum value along the Y axis. Should be greater than ymin.
Example The example below populates an array of data with a Gaussian distribution and creates a custom 2D plot with explicit axes limits in X and Y.
Sub Main
'USER SETUP Dim xstart As Double, xend As Double Dim amp As Double, width As Double Dim nsamps As Long xstart = -10 xend = 10 nsamps = 201 amp = 1 width = 2
' Create a linear array of numbers from min to max Dim xvals( ) As Double ReDim xvals( nsamps-1 ) linspace( xstart, xend, nsamps, xvals() )
' Populate the Gaussian function to plot Dim xfunc() As Double ReDim xfunc( nsamps-1 ) Dim curx As Long For curx = 0 To UBound( xvals, 1 ) xfunc( curx ) = gauss( xvals( curx ), amp, width ) Next curx
' Create a 2D plot instance Dim plotid As Long plotid = AddUser2DPlot()
' Dimension the plot object as Chart2D so we can see the object's methods and variables in the editor Dim plotobj As Chart2D Set plotobj = GetObjUser2DPlot( plotid )
' Set generic graph information so you can see where they show up in the plot SetUser2DPlotWindowTitle( plotid, "Window Title" ) SetUser2DPlotGraphTitle( plotid, "Graph Title" ) SetUser2DPlotXaxisTitle( plotid, "X Axis Title" ) SetUser2DPlotYaxisTitle( plotid, "Y Axis Title" ) SetUser2DPlotInfoText( plotid, "Info text entry" )
' Add the data series to the plot Dim plotseries( 2 ) As Long plotseries( 0 ) = AddUser2DPlotSeries( plotid, xvals(), xfunc() ) SetUser2DPlotXLimitsAuto( plotid, False ) SetUser2DPlotXLimits( plotid, xstart, xend ) SetUser2DPlotYLimitsAuto( plotid, False ) SetUser2DPlotYLimits( plotid, 0, amp*1.1 ) SetUser2DPlotLegendLabel( plotid, 1, "A=" & CStr(amp) & ", W=" & CStr(width) )
End Sub
Sub linspace( ByVal d_start As Double, _ ByVal d_end As Double, _ ByVal num_samps As Long, _ ByRef ret_vals() As Double )
Dim cur_ind As Long cur_ind = 0 Dim cur_samp As Double For cur_samp = d_start To d_end+0.0001 Step (d_end-d_start)/(num_samps-1) ret_vals( cur_ind ) = cur_samp cur_ind = cur_ind + 1 Next cur_samp
End Sub
Function gauss( x_val, amp, width ) As Double
gauss = amp * Exp( -2 * ( x_val / width )^2 )
End Function
See Also
|