octave-maintainers
[Top][All Lists]
Advanced

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

Re: fast scatter plots - advice sought


From: David Bateman
Subject: Re: fast scatter plots - advice sought
Date: Mon, 01 Feb 2010 17:10:37 +0100
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706)

Jaroslav Hajek wrote:
On Fri, Jan 15, 2010 at 3:06 PM, dbateman <address@hidden> wrote:
Ok, so given this and the feedback from Shai both scatter and the gnuplot
backend do the wrong thing here. I'll fix this over the weekend.

Thanks
David


I didn't quite follow the information flow, but I noted that if in
Matlab you do scatter (x, y, s, c) where x, y, c are long column
vectors and s is a scalar, Matlab creates a single patch that can
handle the varying color, through property VertexCData or something
like that. Is this possible for Octave? If so, then in this case one
would not need to split by unique colors and sizes, but just by sizes,
which would probably be much faster when variable colors are used.

OTOH, when colors are specified as a full RGB Nx3 array, Matlab (2007)
seems to invariably make one patch per point.

Jaroslav,

It appears that gnuplot can handle a PM3D palette for lines in 2 and 3D, so can be quite easily handled in gnuplot itself. Something like the attached patch seems to work and the example

n=5000;x = randn(1,n); y = randn(1,n); c = sqrt(x.^2+y.^2); h = scatter(x,y,6,c)

is now quite fast with gnuplot. Do you see any issues with making a change like this?

D.

diff --git a/scripts/plot/__go_draw_axes__.m b/scripts/plot/__go_draw_axes__.m
--- a/scripts/plot/__go_draw_axes__.m
+++ b/scripts/plot/__go_draw_axes__.m
@@ -762,10 +762,10 @@
                   if (numel(ccol) == 3)
                     color = ccol;
                   else
-                    r = 1 + round ((size (cmap, 1) - 1)
-                                   * (ccol - clim(1))/(clim(2) - clim(1)));
-                    r = max (1, min (r, size (cmap, 1)));
-                    color = cmap(r, :);
+                     if (isscalar (ccol))
+                       ccol = repmat(ccol, numel (xcol), 1);
+                     endif
+                     color = "flat";
                   endif
                 elseif (strncmp (ec, "interp", 6))
                   warning ("\"interp\" not supported, using 1st entry of 
cdata");
@@ -859,8 +859,12 @@
             if (mono)
               colorspec = "";
             else
-              colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
-                                   round (255*color));
+               if (ischar (color))
+                 colorspec = "palette";
+               else
+                colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                     round (255*color));
+               endif
             endif
 
              sidx = 1;
@@ -993,20 +997,40 @@
               withclause{data_idx} = tmpwith{1};
              endif
             if (nd == 3)
-              if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol))
-                data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ...
-                                  [zcol; zcol(1)]]';
-              else
-                data{data_idx} = [xcol, ycol, zcol]';
-              endif
-              usingclause{data_idx} = sprintf ("record=%d using 
($1):($2):($3)", columns (data{data_idx}));
+               if (ischar (color))
+                if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol))
+                  data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ...
+                                    [zcol; zcol(1)]]';
+                else
+                  data{data_idx} = [xcol, ycol, zcol]';
+                endif
+                usingclause{data_idx} = sprintf ("record=%d using 
($1):($2):($3)", columns (data{data_idx}));
+               else
+                if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol))
+                  data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ...
+                                    [zcol; zcol(1)], [ccol; ccol(1)]]';
+                else
+                  data{data_idx} = [xcol, ycol, zcol, ccol]';
+                endif
+                usingclause{data_idx} = sprintf ("record=%d using 
($1):($2):($3):($4)", columns (data{data_idx}));
+               endif
             else
-              if (! isnan (xcol) && ! isnan (ycol))
-                data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]';
-              else
-                data{data_idx} = [xcol, ycol]';
-              endif
-              usingclause{data_idx} = sprintf ("record=%d using ($1):($2)", 
columns (data{data_idx}));
+               if (ischar (color))
+                if (! isnan (xcol) && ! isnan (ycol))
+                  data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ...
+                                     [ccol; ccol(1)]]';
+                else
+                  data{data_idx} = [xcol, ycol, ccol]';
+                endif
+                usingclause{data_idx} = sprintf ("record=%d using 
($1):($2):($3)", columns (data{data_idx}));
+               else
+                if (! isnan (xcol) && ! isnan (ycol))
+                  data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]';
+                else
+                  data{data_idx} = [xcol, ycol]';
+                endif
+                usingclause{data_idx} = sprintf ("record=%d using ($1):($2)", 
columns (data{data_idx}));
+               endif
             endif
 
             if (length (tmpwith) > 1)
diff --git a/scripts/plot/private/__scatter__.m 
b/scripts/plot/private/__scatter__.m
--- a/scripts/plot/private/__scatter__.m
+++ b/scripts/plot/private/__scatter__.m
@@ -186,18 +186,7 @@
     if (ischar (c) || rows (c) == 1)
       h = render_size_color (hg, vert, s, c, marker, filled, false); 
     else
-      [cc, idx] = unique_idx (c, "rows");
-      if (isscalar (s))
-        for i = 1:rows (x)
-          h = render_size_color (hg, vert(idx{i},:), s, cc(i,:), 
-                                 marker, filled, true);
-        endfor
-      else
-        for i = 1:rows (x)
-          h = render_size_color (hg, vert(idx{i},:), s(idx{i}), cc(i,:), 
-                                 marker, filled, true);
-        endfor
-      endif
+      h = render_size_color (hg, vert, s, c, marker, filled, true); 
     endif
 
   endif

reply via email to

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