\cancel mode verify ! error_bars.jnl ! 6/99 *sh* ! 7/01 *acm* update /xlimits to /hlimits ! Description: Overlay error bars on a plot ! Usage: $1 $2 $3 $4 $5 ! yes? GO error_bars plot_command base errors [err_down] ["transpose"] ! $1 - the plot command with qualifiers (eg PLOT/VS/OVER/LINE=2) ! $2 - underlying points to be marked with error bars ! $3 - error values associated with points (or error limit above) ! $4 - [optional] error limit below (if different that $4) ! $5 - [optional] "transpose" to interchange X and Y axes ! examples ! demo script has more examples ! yes? go error_bars_demo ! Define synthetic data ! yes? let xpts = j[j=1:5] ! yes? let ypts = sin(xpts) ! yes? let errup = 0.6 * RANDU(xpts) ! yes? let errdn = 0.6 * RANDU(xpts+1) ! ! yes? plot/hlimits=0:6/vlimits=-2:2/vs/line xpts, ypts ! yes? GO error_bars poly/line=2 ypts errup ! yes? GO error_bars poly/line=3 ypts errup errdn ! argument check QUERY/IGNORE $1%1" THEN LET/QUIET ERBerr_dn = ($4) ELSE LET/QUIET ERBerr_dn = ERBerr_up ENDIF DEFINE SYMBOL ERBis_transposed $5"0|*>1" ! determine the orientation of the data (and check that it is 1D) DEFINE SYMBOL ERBax `ERBy,return=shape` DEFINE SYMBOL ERBbar_dim ($ERBax"|PT>Z|X>Z|Y>Z|Z>Y|T>Z|i|Y>j|Z>k|T>l") ! get the dependent coordinates -- needed since POLYGON is like PLOT/VS ! typically, "0*ERBy + X[i=lo:hi]", so X is inherited from ERBy DEFINE SYMBOL ERBilo `ERBy,return=($ERBiax)start` DEFINE SYMBOL ERBihi `ERBy,return=($ERBiax)end` LET/QUIET ERBx_raw = 0*ERBy + ($ERBax) LET/QUIET ERBx = ERBx_raw[($ERBiax)=($ERBilo):($ERBihi)] ! Z axis plots have a reversed sense of "transposed" IF ($ERBax"|Z>1|*>0") THEN DEFINE SYMBOL ERBis_transposed ($ERBis_transposed"|0>1|1>0") ENDIF IF ($ERBis_transposed) THEN DEFINE SYMBOL ERBtranspz "/transpose" ELSE CANCEL SYMBOL ERBtranspz ENDIF ! determine the orientation for the error bar coordinates LET/QUIET ERBxbar = ($ERBbar_dim)SEQUENCE({0,0,-1,1,0}) LET/QUIET ERBybar = ($ERBbar_dim)SEQUENCE({0,1, 1,1,1}) ! scale the "T" on the error bar based on the to data ... ! NOTE: define the symbol "IbeamWidth" to control the cross bar IF ($ERBtranspz"0|*>1) THEN LET/QUIET ERBwidth = ($IbeamWidth".005") * (($YAXIS_MAX"1")-(($YAXIS_MIN"0"))) ELSE LET/QUIET ERBwidth = ($IbeamWidth".005") * (($XAXIS_MAX"1")-(($XAXIS_MIN"0"))) ENDIF $1($ERBtranspz"/over")/over/coord=($ERBbar_dim)) ERBx+ERBxbar*ERBwidth,ERBy+ERBerr_up*ERBybar $1($ERBtranspz"/over")/over/coord=($ERBbar_dim)/NOLABEL ERBx+ERBxbar*ERBwidth,ERBy-ERBerr_dn*ERBybar cancel symbol ERB* cancel variable ERB* set mode/last verify