help-octave
[Top][All Lists]
Advanced

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

Re: bar and hist


From: David Bateman
Subject: Re: bar and hist
Date: Tue, 06 Nov 2007 14:33:49 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Kai Habel wrote:
> -------- Original-Nachricht --------
>   
>> Datum: Tue, 06 Nov 2007 13:59:44 +0100
>> Von: David Bateman <address@hidden>
>> An: Evan <address@hidden>
>> CC: kahacjde <address@hidden>, address@hidden
>> Betreff: Re: bar and hist
>>     
>
>   
>> Evan wrote:
>>     
>>> On Nov 5, 2007 5:48 PM, David Bateman <address@hidden>
>>>       
>> wrote:
>>     
>>>   
>>>       
>>>> Evan wrote:
>>>>     
>>>>         
>>>>> On 10/31/07, kahacjde <address@hidden> wrote:
>>>>>
>>>>>       
>>>>>           
>>>>>> Hello,
>>>>>>
>>>>>> bar and hist are using 'patch' graphic objects now. You have to
>>>>>>             
>> change the
>>     
>>>>>> patch properties like this:
>>>>>>
>>>>>> h = bar(rand(10,1));
>>>>>> set(h,'FaceColor','yellow','EdgeColor',[0.2 0.7 0.4]);
>>>>>>
>>>>>> or in one line
>>>>>>
>>>>>> bar(rand(10,1), 'FaceColor', 'yellow', 'EdgeColor', [0.2 0.7 0.4]);
>>>>>>
>>>>>> Kai
>>>>>>
>>>>>>         
>>>>>>             
>>>>> It seems that this doesn't work for hist
>>>>>
>>>>>       
>>>>>           
>>>> This works fine for me.. All of the additional arguments to bar are
>>>> passed to the underlying patch command.. So this should work..
>>>>
>>>>     
>>>>         
>>> Could you please give me an example, or refer me to the document.
>>> I cannot get it work in that way.
>>>
>>>   
>>>       
>> Ok, I tested for bar and not hist.. Yes in hist the additional arguments
>> are not passed not.. Here is a patch that addresses this
>>
>> D.
>>
>>
>> -- 
>> David Bateman                                address@hidden
>> Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
>> Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
>> 91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 
>>
>> The information contained in this communication has been classified as: 
>>
>> [x] General Business Information 
>> [ ] Motorola Internal Use Only 
>> [ ] Motorola Confidential Proprietary
>>
>>     
>
> David,
>
> matlab does not support property/value pairs for hist. I tried this for 
> version 7.5
>
>   
>>> hist(randn(30),'FaceColor','red')
>>>       
> ??? Error using ==> hist at 45
> Input arguments must be numeric.
>
>
> They propose to use the following method instead:
>
> hist(randn(30)) 
> h = findobj(gca,'Type','patch');
> set(h,'FaceColor','red','EdgeColor','white')
>
> Kai
>
>   
Hum, I suspect thats more an oversight on their part. I see no reason
not to support it. That being said the method that matlab suggests also
works fine in 2.9.16

However, I note that Octave 2.9.16 doesn't allow hist(randn(30)) and so
I needed to slightly modify the patch.. Update attached.


D.


-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** ./scripts/plot/hist.m.orig3 2007-11-06 13:56:45.263951652 +0100
--- ./scripts/plot/hist.m       2007-11-06 14:31:49.525374328 +0100
***************
*** 43,51 ****
  
  ## Author: jwe
  
! function [nn, xx] = hist (y, x, norm)
  
!   if (nargin < 1 || nargin > 3)
      print_usage ();
    endif
  
--- 43,51 ----
  
  ## Author: jwe
  
! function [nn, xx] = hist (y, varargin)
  
!   if (nargin < 1)
      print_usage ();
    endif
  
***************
*** 56,73 ****
    endif
  
    if (isreal (y))
!     max_val = max (y);
!     min_val = min (y);
    else
      error ("hist: first argument must be a vector");
    endif
  
!   if (nargin == 1)
      n = 10;
      x = [0.5:n]'/n;
      x = x * (max_val - min_val) + ones(size(x)) * min_val;
    else
      ## nargin is either 2 or 3
      if (isscalar (x))
        n = x;
        if (n <= 0)
--- 56,75 ----
    endif
  
    if (isreal (y))
!     max_val = max (y(:));
!     min_val = min (y(:));
    else
      error ("hist: first argument must be a vector");
    endif
  
!   iarg = 1;
!   if (nargin == 1 || ischar (varargin{iarg}))
      n = 10;
      x = [0.5:n]'/n;
      x = x * (max_val - min_val) + ones(size(x)) * min_val;
    else
      ## nargin is either 2 or 3
+     x = varargin {iarg++};
      if (isscalar (x))
        n = x;
        if (n <= 0)
***************
*** 113,120 ****
  
    freq = diff (chist);
  
!   if (nargin == 3)
      ## Normalise the histogram.
      freq = freq / rows (y) * norm;
    endif
  
--- 115,123 ----
  
    freq = diff (chist);
  
!   if (nargin > 2 && !ischar (varargin{iarg}))
      ## Normalise the histogram.
+     norm = varargin{iarg++};
      freq = freq / rows (y) * norm;
    endif
  
***************
*** 126,133 ****
        nn = freq;
        xx = x;
      endif
    else
!     bar (x, freq, 1.0);
    endif
  
  endfunction
--- 129,138 ----
        nn = freq;
        xx = x;
      endif
+   elseif (size (freq, 2) != 1)
+     bar (x, freq, 0.8, varargin{iarg:end});
    else
!     bar (x, freq, 1.0, varargin{iarg:end});
    endif
  
  endfunction
2007-11-06  David Bateman  <address@hidden>

        * plot/hist.m: Pass any additional arguments to bar for
        treatment. Create a default x value that is always a vector.

reply via email to

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