From octave-sources-request at bevo dot che dot wisc dot edu Tue Jun 24 08:23:54 2003 Subject: control contour levels From: Fabian at isas-berlin dot de To: octave-sources at bevo dot che dot wisc dot edu Date: Tue, 24 Jun 2003 08:13:18 -0500 I needed better control over Gnuplot's 'set cntrparam' and 'set clabel' commands from within Octave. The following function-script matches my needs. It needs 'mat2str.m', which can be also be found on this list ( 2002 ) or in latest octave-forge package. Rolf Fabian ----------------- snip ------------------- snap ---------------------------------------- %USAGE clevel( ) ** NO REPLOT ** % set default contour parameters % % clevel( 's' ) ** NO REPLOT ** % show contour parameter settings % % clevel( STR ) ** REPLOT ** % available STR : % 'li'near smooth % 'bs'pline smoother % 'cu'bicspline smoothest contours % 'aNUM' number of automatic levels % 'oNUM' order NUM % 'pNUM' points NUM % 'no' same as 'unset clabel' % 'yes' same as 'set clabel' % '%5.2f' clabel format % % clevel( VECTOR of z levels ) ** REPLOT ** % replot with given 'discrete' contour levels % %ASSOC Gnuplot commands : % set contour, set cntrparam, set clabel, set surface % Octave functions : graw, gsplot, contour. % Octave-forge : 'mat2str.m' needed. % %NOTES Instead of Gnuplots 'increment' option % "gset cntrparam levels increment ,," % use: clevel( :: ) % %Author (C) 2003 Rolf Fabian 030624 % published under current GNU GENERAL PUBLIC LICENSE %030623 init function clevel(arg) if nargin>1, usage( \ "clevel(), clevel('s'), clevel(STRING), clevel(VECTOR)" ); endif if ~nargin % set defaults % ------------------------------------------------ % % Current Gnuplot ( 3.8j ) defaults are % 'li'near, 5 points, order 4, 5 auto levels. % By default, Label is on and label-format is '%8.3g'. % I personally prefer smoother contours by default! % Hence I use 'bs'pline mode. % A third possibility is 'cu'bicsplines. SMOOTH='bs'; % Select from 'li','bs','cu' POINTS= 5; % see Gnuplot help ORDER = 4; % see Gnuplot help LEVELS= 5; % 'auto'matic levels LABFMT='%8.3g'; % Label-format LABEL = 1; % switch off: change to 0 % ------------------------------------------------ % graw( sprintf('set cntrparam %s\n', SMOOTH) ); graw( sprintf('set cntrparam p %d\n', POINTS) ); graw( sprintf('set cntrparam o %d\n', ORDER ) ); graw( sprintf('set cntrparam le au %d\n', LEVELS) ); % always set to default format % even if LABEL=0 (switched off) graw( sprintf("set clabel '%s'\n", LABFMT) ); if ~LABEL % switch off graw( "unset clabel '%s'\n" ); endif else L = length( arg ); if isstr( arg ) arg = tolower( arg ); if L==1 && arg=='s' graw('show cntrparam\n'); return; elseif arg(1)=='a' % auto levels NUM NUM= str2num( arg(2:length(arg)) ) graw( sprintf( 'set cntrparam le au %d\n',NUM) ); elseif arg(1)=='o' % smooth order NUM NUM= str2num( arg(2:length(arg)) ); graw( sprintf( 'set cntrparam or %d\n',NUM) ); elseif arg(1)=='p' % points NUM NUM= str2num( arg(2:length(arg)) ); graw( sprintf( 'set cntrparam po %d\n',NUM) ); elseif arg(1)=='%' % clabel format graw( sprintf( "set clabel '%s'\n", arg) ); elseif L==2 && arg=='no' % switch-off clabel graw( sprintf( "unset clabel\n") ); elseif L==3 && arg=='yes' % switch-on clabel % using previous format graw( sprintf( "set clabel\n") ); else if arg(1:2)=='li', graw('set cntrparam li\n'); elseif arg(1:2)=='bs', graw('set cntrparam bs\n'); elseif arg(1:2)=='cu', graw('set cntrparam cu\n'); else error(\ "clevel: unknown argument \'%s\'",arg); end end replot; elseif isvector( arg ) arg=arg(:).'; % prepare for 'mat2str' if iscomplex( arg ) error( "clevel: complex z-levels invalid." ); endif z = mat2str( arg ); if L>1 z( length(z) )=''; % rm '[' and ']' z( 1 )=''; endif graw( sprintf("set cntrparam lev dis %s\n", z ) ); replot; else error( "clevel: invalid argument." ); endif endif endfunction %!demo %! clevel; % init with defined settings %! clevel('s') % show them %! graw('set size square\n'); %! title('default'); %! N=15; contour( randn(N) ); % plot %! W = 5; % pause W seconds %! pause(W); s='linear'; title(s); clevel(s) %! pause(W); s='cubics'; title(s); clevel(s) %! pause(W); s='o2'; title(s); clevel(s) %! pause(W); s='p3'; title(s); clevel(s) %! pause(W); title('increment'); %! clevel( -0.5:0.25:0.5 ) %! pause(W); title( 'discrete' ); %! clevel( [-0.123,-0.1,0.1,+0.34] ) %! pause(W); s= '%.3f'; title(s); clevel( s ) %! pause(W); title( 'switch off labels' ); clevel('no') %! pause(W); title( 'restore labels at prev dot FMT' ); clevel('yes') %! title(''); clevel; % back to defaults %! graw('set size nosquare\n');