help-octave
[Top][All Lists]
Advanced

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

Re: scatter-plotting by color


From: Paul Kienzle
Subject: Re: scatter-plotting by color
Date: Thu, 20 Dec 2001 15:16:19 -0500

On Thu, Dec 20, 2001 at 02:15:35PM -0500, John Day wrote:
> Paul,
> 
> Thanks for the tips. But I coudn't get it to run. hsv(), eopen(), 
> eglobar(), eaxes() etc are all undefined on my system. Do I need some 
> special toolbox for this?

Sorry. I've gotten a bit comfortable in my octave-forge world  :-)

hsv is part of octave-forge (http://octave.sf.net).  Any
colormap will work, but hsv works particularly well in this case
because it scatters the colours about the rainbow rather than 
differentiating on the basis of dark or pale they are.

sparse is also part of octave-forge.  You can either use main/sparse
or extra/fake-sparse since I'm just using sparse to fill A(i,j)=c
for vectors i,j and c.

conv2 is also part of octave-forge.  You don't really need it since
you can use a smaller array and scale it up with imagesc.

EpsTk (http://www.epstk.de/) is not needed for this example since
imagesc will work.  The advantage of epstk is that you can plot
images with labelled x- and y-axes.  plplot may also allow this,
you will have to check for yourself.

Here is an example which should work in base octave:

   # define a rainbow colormap with a white background
   # (from rainbow.m courtesy of Kai Habel)
   x = linspace (0, 1, 64)';
   r = (x < 2/5) + (x >= 2/5 & x < 3/5) .* (-5 * x + 3)\
     + (x >= 4/5) .* (10/3 * x - 8/3);
   g = (x < 2/5) .* (5/2 * x) + (x >= 2/5 & x < 3/5)\
     + (x >= 3/5 & x < 4/5) .* (-5 * x + 4);
   b = (x >= 3/5 & x < 4/5) .* (5 * x - 3) + (x >= 4/5);
   map = [r, g, b];
   map(1,:)=1; # set background to white
   colormap(map);

   # generate some data
   x = rand(30,1);
   y = rand(size(x));
   C = rand(size(x));

   # convert your x,y coordinates to image coordinates
   N=200;
   xi = 1+round((x-min(x))/(max(x)-min(x))*(N-1));
   yi = 1+round((y-min(y))/(max(y)-min(y))*(N-1));

   # build a sparse matrix with '.' at the coordinates
   do_fortran_indexing = 1;
   A = zeros(N);
   A((yi-1)*N+xi) = C;

   # display the matrix as an image
   imagesc(A,2);

- Paul

> 
> I'm running Octave version 2.1.33 (i586-pc-cygwin).
> 
> -jday
> 
> At 12:22 PM 12/20/01 -0500, Paul Kienzle wrote:
> >AFAIK, gnuplot doesn't have fine grained color control, so you might have
> >trouble with this.  I don't know about plplot.
> >
> >Here's a possibility:
> >
> >         # generate some data
> >         x = rand(30,1);
> >         y = rand(size(x));
> >         C = rand(size(x));
> >         # define a colormap that uses different colors for all its points
> >         map=hsv(64);
> >         map(1,:)=[1,1,1];
> >         colormap(map);
> >         # convert your x,y coordinates to image coordinates
> >         xi = 1+round((x-min(x))/(max(x)-min(x))*399);
> >         yi = 1+round((y-min(y))/(max(y)-min(y))*399);
> >         # use implicit sparse->full conversion to build an image array
> >         # use conv2 to spread spread the points out a bit (ones(5) makes
> >         # them into a 5x5 square, but you could easily define another shape
> >         matrix = conv2(sparse(xi,yi,C,400,400),ones(5),'same');
> >         # if we had a proper image viewer, we could define the x and y
> >         # axes as well:
> >         xstep = linspace(min(x),max(x),400);
> >         ystep = linspace(min(y),max(y),400);
> >         imagesc(xstep,ystep,matrix);
> >         # or if you have epsTk:
> >         eopen("scatter.ps");
> >         eglobpar;
> > 
> >eaxes([min(x),(max(x)-min(x))/10,max(x)],[min(y),(max(y)-min(y))/10,max(y)]);
> >         eimagesc(matrix,map,'e');
> >         eclose
> >         eview
> >
> >Paul Kienzle
> >address@hidden
> >
> >On Wed, Dec 19, 2001 at 07:24:59PM -0500, John Day wrote:
> > > I have a file of 3-tuples (X,Y,C), where C is an integer 1-16, which I 
> > want
> > > to scatter-plot, X by Y with C determining the color of the plotted dots.
> > >
> > > Does anyone know or have a ready-made function to do this? I don't care
> > > what the colors are as long as they are unique for each value of C.
> > > Different-shaped dots will do if we run out of colors.
> > >
> > > Thanks,
> > > John Day
> > >
> > >
> > >
> > > -------------------------------------------------------------
> > > 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
> > > -------------------------------------------------------------
> > >
> 
> 
> 
> -------------------------------------------------------------
> 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
> -------------------------------------------------------------
> 



-------------------------------------------------------------
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]