[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch for bar objects
From: |
David Bateman |
Subject: |
Re: Patch for bar objects |
Date: |
Mon, 19 Nov 2007 11:55:58 +0100 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Michael Goffioul wrote:
> On 11/19/07, David Bateman <address@hidden> wrote:
>
>> Michael,
>>
>> I suspect that this is against 2.9.17.. Note that __bar__.m was
>> significantly changed to allow colormaps to affect the bar colors and to
>> allow legends in for the bar charts. You patch doesn't apply to the
>> CVS.. Could you supply something that works with the CVS copy of __bar__.m?
>>
>
> The patch is against latest CVS...
> The fact is that your changes haven't been applied to CVS yet.
>
> Michael.
>
>
Ok, sorry I have 4 patches unapplied at the moment and missed that this
wasn't applied yet.. Ok, we are going to have a conflict between our
patches as well, if John applies them separately. Therefore please
consider the attached patch that combines both of our patches into a
single contribution..
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/image/Makefile.in.orig9 2007-11-15 11:00:46.627166730 +0100
--- ./scripts/image/Makefile.in 2007-11-15 11:02:12.241119258 +0100
***************
*** 34,42 ****
INSTALL_DATA = @INSTALL_DATA@
SOURCES = __img__.m __img_via_file__.m autumn.m bone.m brighten.m colormap.m \
! cool.m copper.m flag.m gray.m gray2ind.m hot.m hsv.m hsv2rgb.m image.m \
! image_viewer.m imagesc.m imshow.m ind2gray.m ind2rgb.m jet.m loadimage.m \
! ntsc2rgb.m ocean.m pink.m prism.m rainbow.m rgb2hsv.m rgb2ind.m \
rgb2ntsc.m saveimage.m spring.m summer.m white.m winter.m
IMAGES = default.img
--- 34,42 ----
INSTALL_DATA = @INSTALL_DATA@
SOURCES = __img__.m __img_via_file__.m autumn.m bone.m brighten.m colormap.m \
! cool.m copper.m flag.m gmap40.m gray.m gray2ind.m hot.m hsv.m hsv2rgb.m \
! image.m image_viewer.m imagesc.m imshow.m ind2gray.m ind2rgb.m jet.m \
! loadimage.m ntsc2rgb.m ocean.m pink.m prism.m rainbow.m rgb2hsv.m rgb2ind.m
\
rgb2ntsc.m saveimage.m spring.m summer.m white.m winter.m
IMAGES = default.img
*** ./scripts/image/gmap40.m.orig9 2007-11-15 11:00:53.351851236 +0100
--- ./scripts/image/gmap40.m 2007-11-15 11:31:58.717360317 +0100
***************
*** 0 ****
--- 1,49 ----
+ ## Copyright (C) 2007 David Bateman
+ ##
+ ## This file is part of Octave.
+ ##
+ ## Octave is free software; you can redistribute it and/or modify it
+ ## under the terms of the GNU General Public License as published by
+ ## the Free Software Foundation; either version 3 of the License, or (at
+ ## your option) any later version.
+ ##
+ ## Octave is distributed in the hope that it will be useful, but
+ ## WITHOUT ANY WARRANTY; without even the implied warranty of
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ## General Public License for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License
+ ## along with Octave; see the file COPYING. If not, see
+ ## <http://www.gnu.org/licenses/>.
+
+ ## -*- texinfo -*-
+ ## @deftypefn {Function File} {} gmap40 (@var{n})
+ ## Create a color colormap. The colormap is red, green, blue, yellow,
+ ## magneta and cyan. These are the colors that are allowed with patch
+ ## objects using gnuplot 4.0, and so this colormap function is specially
+ ## designed for users of gnuplot 4.0. The argument @var{n} should be
+ ## a scalar. If it is omitted, a length of 6 is assumed. Larger values
+ ## of @var{n} result in a repetition of the above colors
+ ## @seealso{colormap}
+ ## @end deftypefn
+
+ function map = gmap40 (number)
+
+ if (nargin == 0)
+ number = 6;
+ elseif (nargin == 1)
+ if (! isscalar (number))
+ error ("gmap40: argument must be a scalar");
+ endif
+ else
+ print_usage ();
+ endif
+
+ if (number >= 1)
+ map = repmat ([1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1],
+ ceil (number / 6), 1) (1:number, :);
+ else
+ map = [];
+ endif
+
+ endfunction
*** ./scripts/plot/__bars__.m.orig9 2007-11-19 11:51:05.000203818 +0100
--- ./scripts/plot/__bars__.m 2007-11-19 11:50:19.930528888 +0100
***************
*** 0 ****
--- 1,59 ----
+ ## Copyright (C) 1996, 1997, 2007 John W. Eaton
+ ##
+ ## This file is part of Octave.
+ ##
+ ## Octave is free software; you can redistribute it and/or modify it
+ ## under the terms of the GNU General Public License as published by
+ ## the Free Software Foundation; either version 3 of the License, or (at
+ ## your option) any later version.
+ ##
+ ## Octave is distributed in the hope that it will be useful, but
+ ## WITHOUT ANY WARRANTY; without even the implied warranty of
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ## General Public License for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License
+ ## along with Octave; see the file COPYING. If not, see
+ ## <http://www.gnu.org/licenses/>.
+
+ ## Undocumented internal function.
+
+ ## Author: jwe
+
+ function tmp = __bars__ (h, vertical, x, y, xb, yb, width, group,
have_color_spec, varargin)
+
+ ycols = columns (y);
+ clim = get (h, "clim");
+
+ if (vertical)
+ tmp = [];
+ for i = 1 : ycols
+ if (! have_color_spec)
+ if (ycols == 1)
+ lev = clim (1);
+ else
+ lev = (i - 1) * (clim(2) - clim(1)) / (ycols - 1) - clim(1);
+ endif
+ tmp = [tmp; patch(xb(:,:,i), yb(:,:,i), "FaceColor", "flat",
+ "cdata", lev, varargin {:})];
+ else
+ tmp = [tmp; patch(xb(:,:,i), yb(:,:,i), varargin {:})];
+ endif
+ endfor
+ else
+ tmp = [];
+ for i = 1 : ycols
+ if (! have_color_spec)
+ if (ycols == 1)
+ lev = clim (1)
+ else
+ lev = (i - 1) * (clim(2) - clim(1)) / (ycols - 1) - clim(1);
+ endif
+ tmp = [tmp; patch(yb(:,:,i), xb(:,:,i), "FaceColor", "flat",
+ "cdata", lev, varargin {:})];
+ else
+ tmp = [tmp; patch(yb(:,:,i), xb(:,:,i), varargin {:})];
+ endif
+ endfor
+ endif
+ endfunction
*** ./scripts/plot/Makefile.in.orig9 2007-11-19 11:53:41.866097876 +0100
--- ./scripts/plot/Makefile.in 2007-11-19 11:53:46.038881983 +0100
***************
*** 38,43 ****
--- 38,44 ----
__axes_limits__.m \
__axis_label__.m \
__bar__.m \
+ __bars__.m \
__contour__.m \
__default_plot_options__.m \
__errcomm__.m \
*** ./scripts/plot/bar.m.orig9 2007-11-15 10:52:38.261060183 +0100
--- ./scripts/plot/bar.m 2007-11-15 10:53:38.296024463 +0100
***************
*** 23,28 ****
--- 23,29 ----
## @deftypefnx {Function File} {} bar (@var{x}, @var{y}, @var{w})
## @deftypefnx {Function File} {} bar (@var{x}, @var{y}, @var{w}, @var{style})
## @deftypefnx {Function File} address@hidden =} bar (@dots{}, @var{prop},
@var{val})
+ ## @deftypefnx {Function File} {} bar (@var{h}, @dots{})
## Produce a bar graph from two vectors of x-y data.
##
## If only one argument is given, it is taken as a vector of y-values
***************
*** 37,42 ****
--- 38,44 ----
## or @code{"stacked"}.
##
## The optional return value @var{h} provides a handle to the patch object.
+ ## Whereas the option input handle @var{h} allows an axis handle to be passed.
## Properties of the patch graphics object can be changed using
## @var{prop}, @var{val} pairs.
##
*** ./scripts/plot/barh.m.orig9 2007-11-15 10:52:49.856475001 +0100
--- ./scripts/plot/barh.m 2007-11-15 10:53:32.423322054 +0100
***************
*** 22,27 ****
--- 22,28 ----
## @deftypefnx {Function File} {} barh (@var{x}, @var{y}, @var{w})
## @deftypefnx {Function File} {} barh (@var{x}, @var{y}, @var{w},
@var{style})
## @deftypefnx {Function File} address@hidden =} barh (@dots{}, @var{prop},
@var{val})
+ ## @deftypefnx {Function File} {} barh (@var{h}, @dots{})
## Produce a horizontal bar graph from two vectors of x-y data.
##
## If only one argument is given, it is taken as a vector of y-values
***************
*** 36,41 ****
--- 37,43 ----
## or @code{"stacked"}.
##
## The optional return value @var{h} provides a handle to the patch object.
+ ## Whereas the option input handle @var{h} allows an axis handle to be passed.
## Properties of the patch graphics object can be changed using
## @var{prop}, @var{val} pairs.
##
*** ./scripts/plot/contour.m.orig9 2007-11-15 10:30:57.700253858 +0100
--- ./scripts/plot/contour.m 2007-11-15 10:03:26.794557553 +0100
***************
*** 69,75 ****
if (nargout > 0)
c = ctmp;
! h = htmp
endif
endfunction
--- 69,75 ----
if (nargout > 0)
c = ctmp;
! h = htmp;
endif
endfunction
*** ./scripts/plot/__bar__.m.orig9 2007-11-15 10:31:13.573455186 +0100
--- ./scripts/plot/__bar__.m 2007-11-19 11:52:28.587886978 +0100
***************
*** 22,36 ****
function varargout = __bar__ (vertical, func, varargin)
## Slightly smaller than 0.8 to avoid clipping issue in gnuplot 4.0
width = 0.8 - 10 * eps;
group = true;
! if (nargin < 3)
print_usage ();
endif
! if (nargin > 3 && isnumeric (varargin{2}))
x = varargin{1};
if (isvector (x))
x = x(:);
--- 22,57 ----
function varargout = __bar__ (vertical, func, varargin)
+ varargout = cell (nargout, 1);
+ if (isscalar (varargin{1}) && ishandle (varargin{1}))
+ h = varargin{1};
+ if (! strcmp (get (h, "type"), "axes"))
+ error ("%s: expecting first argument to be an axes object", func);
+ endif
+ oldh = gca ();
+ unwind_protect
+ axes (h);
+ [varargout{:}] = __bar2__ (h, vertical, func, varargin{2:end});
+ unwind_protect_cleanup
+ axes (oldh);
+ end_unwind_protect
+ else
+ [varargout{:}] = __bar2__ (gca(), vertical, func, varargin{:});
+ endif
+
+ endfunction
+
+ function varargout = __bar2__ (h, vertical, func, varargin)
+
## Slightly smaller than 0.8 to avoid clipping issue in gnuplot 4.0
width = 0.8 - 10 * eps;
group = true;
! if (nargin < 4)
print_usage ();
endif
! if (nargin > 4 && isnumeric (varargin{2}))
x = varargin{1};
if (isvector (x))
x = x(:);
***************
*** 63,69 ****
newargs = {};
have_line_spec = false;
! while (idx <= nargin -2)
if (isstr (varargin{idx}) && strcmp (varargin{idx}, "grouped"))
group = true;
idx++;
--- 84,90 ----
newargs = {};
have_line_spec = false;
! while (idx <= nargin - 3)
if (isstr (varargin{idx}) && strcmp (varargin{idx}, "grouped"))
group = true;
idx++;
***************
*** 83,89 ****
endif
if (isscalar(varargin{idx}))
width = varargin{idx++};
! elseif (idx == nargin - 2)
newargs = [newargs,varargin(idx++)];
else
newargs = [newargs,varargin(idx:idx+1)];
--- 104,110 ----
endif
if (isscalar(varargin{idx}))
width = varargin{idx++};
! elseif (idx == nargin - 3)
newargs = [newargs,varargin(idx++)];
else
newargs = [newargs,varargin(idx:idx+1)];
***************
*** 107,115 ****
width = width / ycols;
endif
! cutoff = (x(1:end-1) + x(2:end)) / 2;
! delta_p = [(cutoff - x(1:end-1)); (x(end) - cutoff(end))] * width;
! delta_m = [(cutoff(1) - x(1)); (x(2:end) - cutoff)] * width;
x1 = (x - delta_m)(:)';
x2 = (x + delta_p)(:)';
xb = repmat ([x1; x1; x2; x2](:), 1, ycols);
--- 128,135 ----
width = width / ycols;
endif
! cutoff = min (diff (x)) / 2;
! delta_p = delta_m = ones (size (x)) * cutoff * width;
x1 = (x - delta_m)(:)';
x2 = (x + delta_p)(:)';
xb = repmat ([x1; x1; x2; x2](:), 1, ycols);
***************
*** 137,179 ****
xb = reshape (xb, [4, numel(xb) / 4 / ycols, ycols]);
yb = reshape (yb, [4, numel(yb) / 4 / ycols, ycols]);
! color = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1];
! if (vertical)
! if (nargout < 2)
! newplot ();
! tmp = [];
! for i = 1 : ycols
! if (! have_line_spec)
! tmp = [tmp; patch(xb(:,:,i), yb(:,:,i), color(i,:), newargs {:})];
! else
! tmp = [tmp; patch(xb(:,:,i), yb(:,:,i), newargs {:})];
! endif
! endfor
! if (nargout == 1)
! varargout{1} = tmp;
! endif
! else
! varargout{1} = xb;
! varargout{2} = yb;
endif
else
! if (nargout < 2)
! newplot ();
! tmp = [];
! for i = 1 : ycols
! if (! have_line_spec)
! tmp = [tmp; patch(yb(:,:,i), xb(:,:,i), color(i,:), newargs {:})];
! else
! tmp = [tmp; patch(yb(:,:,i), xb(:,:,i), newargs {:})];
! endif
! endfor
! if (nargout == 1)
! varargout{1} = tmp;
! endif
else
varargout{1} = yb;
varargout{2} = xb;
endif
endif
-
endfunction
--- 157,175 ----
xb = reshape (xb, [4, numel(xb) / 4 / ycols, ycols]);
yb = reshape (yb, [4, numel(yb) / 4 / ycols, ycols]);
! if (nargout < 2)
! newplot ();
! tmp = __bars__ (h, vertical, x, y, xb, yb, width, group, have_line_spec,
newargs {:});
! if (nargout == 1)
! varargout{1} = tmp;
endif
else
! if (vertical)
! varargout{1} = xb;
! varargout{2} = yb;
else
varargout{1} = yb;
varargout{2} = xb;
endif
endif
endfunction
*** ./scripts/plot/surface.m.orig9 2007-11-15 11:08:30.132649857 +0100
--- ./scripts/plot/surface.m 2007-11-15 11:07:34.522414956 +0100
***************
*** 123,129 ****
## Make a default surface object.
tmp = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c);
set (tmp, "facecolor","flat");
! set (tmp, varargin {firststring:end});
if (! ishold ())
set (ax, "view", [0, 90], "box", "off", "xgrid", "on", "ygrid", "on",
"zgrid", "on");
--- 123,131 ----
## Make a default surface object.
tmp = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c);
set (tmp, "facecolor","flat");
! if (firststring <= nargin)
! set (tmp, varargin {firststring:end});
! endif
if (! ishold ())
set (ax, "view", [0, 90], "box", "off", "xgrid", "on", "ygrid", "on",
"zgrid", "on");
*** ./scripts/plot/__contour__.m.orig9 2007-11-14 21:36:48.000000000 +0100
--- ./scripts/plot/__contour__.m 2007-11-15 11:18:56.134922260 +0100
***************
*** 57,63 ****
p = [c(:, i1+1:i1+clen), NaN(2, 1)];
endif
! lev = (clev - minlev) * (clim(2) - clim(1)) / (maxlev - minlev) + clim(1);
if (isnan (z))
h = [h; patch(ax, p(1,:), p(2,:), "facecolor", "none",
--- 57,68 ----
p = [c(:, i1+1:i1+clen), NaN(2, 1)];
endif
! if (maxlev == minlev)
! lev = clim(1);
! else
! lev = (clev - minlev) * (clim(2) - clim(1)) / ...
! (maxlev - minlev) + clim(1);
! endif
if (isnan (z))
h = [h; patch(ax, p(1,:), p(2,:), "facecolor", "none",
*** ./doc/interpreter/image.txi.orig9 2007-11-15 11:09:30.636627710 +0100
--- ./doc/interpreter/image.txi 2007-11-15 11:11:59.833123884 +0100
***************
*** 152,157 ****
--- 152,166 ----
@DOCSTRING(winter)
+ An additional colormap is @code{gmap40}. This code map contains only
+ colors with integer values of the red, green and blue components. This
+ workaround a limitation on gnuplot 4.0, that does not allow the color of
+ line or patch objects to be set, and so @code{gmap40} is useful for
+ gnuplot 4.0 users, and in particular in conjunction with the @var{bar},
+ @var{barh} or @var{contour} functions.
+
+ @DOCSTRING(gmap40)
+
@node Plotting on top of Images
@section Plotting on top of Images
*** ./NEWS.orig9 2007-11-15 11:25:52.721405850 +0100
--- ./NEWS 2007-11-15 11:26:51.015370551 +0100
***************
*** 20,25 ****
--- 20,31 ----
and 1 for the R, G and B values. Invalid values are all mapped
to the same color.
+ This also affects patch objects used in the bar, countour, meshc
+ and surfc functions, where the bars and contours will be
+ monochrome. A workaround for this is to type "colormap gmap40"
+ that loads a colormap that in many cases will be adequate for
+ simple bar and contour plots.
+
+ You can control the width of lines using (for example):
line (x, y, "linewidth", 4, "color", [1, 0, 0.5]);
2007-11-19 David Bateman <address@hidden>
* image/gmap40.m: New gnuplot 4.0 specific colormap fucntion.
* image/Makefile.in (SOURCES): Include it.
* plot/__bar__.h: Allow axis handles to be passed. Set the color
of the bars for the colormap.
* plot/bar.m, plot/barh.m: Document that axis handles can be
passed.
* plot/__contour.m: Avoid possible divide by zero error.
* plot/contour.m: Missing semicolon.
* plot/surface.m: Don't attempt to set additional arguments if
there are none.
* plot/Makefile.in (SOURCES): Include __bars__.m
2007-11-19 Michael Goffioul <address@hidden>
* plot/__bar__.m: put bar creation code into separate function
to allow easy hook up from other graphic backends
* plot/__bars__.m: new function containing bar creation code
2007-11-19 David Bateman <address@hidden>
* interpreter/image.txi: Document gmap40.
2007-11-19 David Bateman <address@hidden>
* NEWS: Document the use of "colormap gmap40" to workaround some
gnuplot 4.0 colormap issues.