Lin log axis (xfig example)
Jump to navigation
Jump to search
require("isisscripts"); %%%%%%%%%%%%%%%%%%%%% define function for axis transformation: private define mylinlog_wcs_func (val, opt) { variable brk = opt.brk; variable scl = opt.scl; variable is_array = typeof (val)==Array_Type; variable x = [@val]; variable i1 =[where(x > brk)]; variable i2 =[where(-brk <= x <= brk)]; variable i3 = [where(x < -brk)]; x[i1] = log(x[i1]/brk)+brk*scl; x[i2] = x[i2]*scl ; x[i3] = -log(-x[i3]/brk)-brk*scl; return is_array ? x : x[0] ; } %%%%%%%%%%%%%%%%%%%%% define inverse function for axis transformation: private define mylinlog_wcs_invfunc (val, opt) { variable brk = opt.brk; variable scl = opt.scl; variable is_array = typeof (val)==Array_Type; variable x = [@val]; variable i1 =[where(x > brk)]; variable i2 =[where(-brk <= x <= brk)]; variable i3 = [where(x < -brk)]; x[i1] = exp(x[i1]-brk*scl)*brk; x[i2] = x[i2]/scl ; x[i3] = -exp(-x[i3]-brk*scl)*brk; return is_array ? x : x[0] ; } %% "opt" is ONE optional argument (for more information use, e.g., a non-skalar argument) %% check of array or not is only required due to the different cases. other functions %% can simply use: return f(val); xfig_plot_add_transform ("mylinlog", &mylinlog_wcs_func, &mylinlog_wcs_invfunc, struct{brk=1,scl=1} ); %%%%%%%%%%%% generate some data: variable xlim = 50; variable x = [-(xlim^[1:0:#100]) , [-1:1:#50] , xlim^[0:1:#100] ]; variable y = exp(-1/(0.2+x^2))/(x^2+0.1); variable major = [0,[1,10,50],-dup]; variable minor = [[1:9]*0.1,-dup,[2:9], -dup, 10*[2:4], -dup]; %%%%%%%%%%%% plot data: variable p = xfig_plot_new (14,10); p.world (-(xlim^1.1), -dup, min_max(y); ylog, pady=0.05); p.xaxis(;wcs="mylinlog", minor = minor, major=major); p.x2axis(; ticlabels = 0); p.plot(x,y); p.render("lin_log_axis.pdf");