help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Contour plots


From: Shai Ayal
Subject: Re: Contour plots
Date: Wed, 09 Mar 2005 09:33:52 +0200
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)

Henry,

As I suspected, you are using the contourm version which is for octplot, not gnuplot. I suggest you use Paul K's contour.m which he posted on this thread. Thsi function also deals with the problem Dmitri refered to. I attach it with small modifications (addition of unwind_protect) for your convenience:

function ret = contour(varargin)

  c = contourc(varargin{:});

  held = ishold;

  unwind_protect

  ## decode contourc output format
  i1 = 1;
  while(i1<length(c))
    ii = i1+1:i1+c(2,i1);
    plot(c(1,ii),c(2,ii),';;'); hold on;

    i1 += c(2,i1)+1;
  endwhile

  unwind_protect_cleanup
     if ~held, hold off; end
  end_unwind_protect

  if nargout > 0, ret = c; end

endfunction


Henry F. Mollet wrote:
I now have compiled "contourl.cc" and everything needed should be in correct
location. Then I ran my script producing the contour plots that need
improvement. x, y, and z of last subplot are now in workspace. If I set a
new terminal and then use contourNew at the octave prompt I expected it to
work but octave is complaining about unknown type. "ContourNew" has the
correct "function c = contourNew(varargin)" in the M-file. What should I do
now? Everything is documented below to the best of my abilities.
Henry

octave:6> pwd
/Users/mollet/CandO/MatrixCalc  % Everything I will need is here
octave:7> ls
CUT
contourNew.m
contourc.m
contourl.cc
contourl.o
contourl.oct


octave:3> ScrAbarOalphaContours  % running my Contours script
octave:5> whos
prot  type                       rows   cols  name
====  ====                       ====   ====  ====
 rwd  string                        1     50  mytitle
 rwd  matrix                        1    350  x
 rwd  matrix                      350    350  xx
 rwd  matrix                        1    350  y
 rwd  matrix                      350    350  yy
 rwd  matrix                      350    350  z
% x,y,z of last subplot are in workspcae

octave:4> gset term aqua 0
octave:5> contourNew(x,y,z)
error: can't perform indexing operations for <unknown type> type

*********************************
## Copyright (C) 2003 Shai Ayal
CUT
function c = contourNew(varargin)

  c = contourc(varargin{:});
ca = gca();
  if (isempty(ca))
    cla();
  elseif (strcmp(get(ca,"nextplot"),"replace")),
    cla();
  endif

  ## decode contourc output format
  i1 = 1;
  while(i1<length(c))
    ii = i1+1:i1+c(2,i1);
    line(c(1,ii),c(2,ii));
i1 += c(2,i1)+1;
  endwhile

Endfunction

****************
## Copyright (C) 2003 Shai Ayal
CUT
function c = contourc(varargin)

if (nargin==1)
  vn = 10;
  z = varargin{1};
  x = 1:size(z,1);
  y = 1:size(z,2);
elseif (nargin==2)
  vn = varargin{2};
  z = varargin{1};
  x = 1:size(z,1);
  y = 1:size(z,2);
elseif (nargin==3)
  vn = 10;
  x = varargin{1};
  y = varargin{2};
  z = varargin{3};
elseif (nargin==4)
  vn = varargin{4};
  x = varargin{1};
  y = varargin{2};
  z = varargin{3};
else
  error("Wrong number of arguments");
endif

if (isscalar(vn))
  vv=linspace(min(min(z)),max(max(z)),vn+2)(2:end-1);
else
  vv = unique(sort(vn));
end

## vectorize the x,y vectors, assuming they are output from meshgrid
if ~isvector(x),
  x = x(1,:);
endif

if ~isvector(y),
  y = y(:,1);
endif

## make everyone the right dimensions
if(size(x,2)==1)
  x = x';
endif
if(size(y,2)==1)
  y = y';
endif

## now call contourl for the real work ...
c=contourl(x,y,z,vv);

endfunction
****************



on 3/8/05 7:37 AM, Dmitri A. Sergatskov at address@hidden wrote:


Shai Ayal wrote:

Dmitri, Henry

...


I sent an email with an attachment containing contour.m, __contourc__.cc
and contourc.m. This version should work with gnuplot. If there is a

Yes. Now it uses gnuplot 2-d plotting instead of 2-d projection of
2-d plotting it uses with the current version of contour.


problem with xlabel, it's gnuplot's problem which is strange since
gnuplot is quite robust.

That was the said difference between plot layouts in true
2-d plotting and 2-d view of splot. The latter one apparently
makes more margins for labels and Henry compensated for it
by adding  "gset origin 0.30,-0.07". When used with your new
contour that command pushes plot too low and that clips off
the xlabel. Plot looks fine without it. Sorry for false alarm here.


about suppressing output -- do you mean not plotting anything if there
are no contours?


Currently, with your new contour, if you type
contour(x,y,z)
(no ";" at the end) it prints out on the terminal
the "s" values which I did not ask for.
The desired behavior is:

contour(x,y,z)         --> plots the figure no output on the terminal window
s=contour(x,y,z)     --> plots the figure, returns s, prints s on the terminal
s=contour(x,y,z);    --> plots the figure, returns s, does not print anything

on

the terminal

(compare that with "hist" for example)


Thanks for the input,
Shai

Sincerely,

Dmitri.




--
Shai Ayal, Ph.D.
Head of Research
BioControl Medical BCM
3 Geron St.
Yehud 56100
ISRAEL
Tel:  + 972 3 6322 126
Fax:  + 972 3 6322 125
email: address@hidden



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]