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: Tue, 12 Jan 2010 23:07:18 +0100
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706)

David Bateman wrote:
Jaroslav Hajek wrote:
Perhaps, but performance of plotting *is* a damn good reason. A
scatter plot taking a minute is almost as good as if it didn't work at
all. Just count the people on the ML worried about plotting
performance vs. those that are worried about compatibility of
primitive representations. OK, the fltk backend will improve
performance in general, but this was one case where the lousy
performance was not a backend issue.

The progress of code seems to be

partially working -> working -> fast

Yes a trade off of compatibility for speed at the second step is a choice that can be made, if they incompatibility doesn't cause issues.


Line objects don't support colormaps and the example I gave won't work with Jaroslav's code.. This seems a good reason "to keep" matlab compatibility to
me (ie using patch)


OK, I copied the old patch constructors back in there. Hence, your
example now works. I take it that lines don't support colormaps in
Matlab either?
Exactly, matlab doesn't support colormaps for line object either.

Though note that the mess in __go_draw_axes__ to handle the colormaps will
probably make Jaroslav's change much slower using patch objects, though
still faster for a larger number of points..


Actually, it doesn't seem to be significantly slower for the main
cases I care about (plotting lots of points in the same color).
Ok, but colormaps might be different.

However, the "filled" option does not work now:
lt-octave:1> scatter (rand (1, 20), rand (1, 20), "filled")
error: invalid color specification: flat
error: invalid value for color property "markerfacecolor" (value = flat)
error: called from:
error:   /home/highegg/devel/octave/scripts/plot/private/__scatter__.m
at line 154, column 11
error: /home/highegg/devel/octave/scripts/plot/scatter.m at line 70, column 7

and the result was the same even prior to all these patches. Can
anyone give me a clue how to correct this?
Even line objects didn't support filling till I added the patch

http://hg.savannah.gnu.org/hgweb/octave/rev/3b7e644bb46d

following the thread

http://old.nabble.com/Plot-Bug%3A-'markerfacecolor'-does-not-work-to25562839.html

though I only treated line and surface objects. The reason I didn't treat patch object was that the patch code didn't use the do_linestyle_command function and untangling the mess seemed to be more effort than it was worth. Something like the attached should add the same functionality to the patch objects, but I can't test at the moment as I haven't rebuilt for a while and I'm in the middle of a build. It doesn't untangle the mess but rather duplicates the functionality of the do_linestyle_command function in the patch objects.

D.


After a bit of testing I believe the attached patch does what you want and the code

n=10; x=randn(1,n);y=randn(1,n);c=sqrt(x.^2+y.^2); h= scatter(x,y,40,c,"filled")

works as expected. I committed this patch

D.
# HG changeset patch
# User David Bateman <address@hidden>
# Date 1263333917 -3600
# Node ID dd70982c81a3081d057667671e27c5bdf31fbc54
# Parent  5edee330d4cb9140936bc06946c469f01ef208d1
Allow markerfacecolor and markeredgecolor to be set and used for patch objects

diff --git a/scripts/ChangeLog b/scripts/ChangeLog
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,9 @@
+2010-01-12  David Bateman  <address@hidden>
+
+       * plot/__go_draw_axes_.m:  Allow patch markerfacecolor and 
+       markeredgecolor properties to be used and set the marker colors
+       appropriately.
+
 2010-01-12  Jaroslav Hajek  <address@hidden>, Ben Barrowes  <address@hidden>
 
        * set/private/validargs.m: New function.
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
@@ -711,7 +711,9 @@
           endif
 
            ## patch outline
-          if (! strncmp (obj.edgecolor, "none", 4))
+          if (!(strncmp (obj.edgecolor, "none", 4)
+                  && strncmp (obj.markeredgecolor, "none", 4)
+                  && strncmp (obj.markerfacecolor, "none", 4)))
 
             data_idx++;
              is_image_data(data_idx) = false;
@@ -797,75 +799,184 @@
               if (isfield (obj, "marker"))
                 switch (obj.marker)
                   case "+"
-                    pt = "pt 1";
+                    pt = pt2 = "pt 1";
                   case "o"
                     pt = "pt 6";
+                     pt2 = "pt 7";
                   case "*"
-                    pt = "pt 3";
+                    pt = pt2 = "pt 3";
                   case "."
-                    pt = "pt 0";
+                    pt = pt2 = "pt 0";
                   case "x"
-                    pt = "pt 2";
+                    pt = pt2 = "pt 2";
                   case {"square", "s"}
-                    pt = "pt 5";
+                    pt = "pt 4";
+                    pt2 = "pt 5";
                   case {"diamond", "d"}
                     pt = "pt 13";
+                    pt2 = "pt 14";
                   case "^"
-                    pt = "pt 9";
+                    pt = "pt 8";
+                    pt2 = "pt 9";
                   case "v"
-                    pt = "pt 11";
+                    pt = "pt 10";
+                    pt2 = "pt 11";
                   case ">"
+                    ## FIXME missing point type 
                     pt = "pt 8";
+                    pt2 = "pt 9";
                   case "<"
+                    ## FIXME missing point type 
                     pt = "pt 10";
+                    pt2 = "pt 11";
                   case {"pentagram", "p"}
-                    pt = "pt 4";
+                    ## FIXME missing point type 
+                    pt = pt2 = "pt 3";
                   case {"hexagram", "h"}
-                    pt = "pt 12";
+                    pt = pt2 = "pt 3";
                   case "none"
-                    pt = "";
+                    pt = pt2 = "";
                   otherwise
-                    pt = "";
+                    pt = pt2 = "";
                 endswitch
               endif
             else
               pt = "";
             endif
 
-            style = "lines";
-            if (isempty (lt))
-              if (! isempty (pt))
-                style = "points";
-              endif
-            elseif (! isempty (pt))
-              style = "linespoints";
-            endif
-
-            if (isfield (obj, "markersize"))
-              if (length (mdat) == nc)
-                m = mdat(i);
-              else
-                m = mdat;
-              endif
-              if (! strcmpi (style, "lines"))
-                ps = sprintf("pointsize %f", m);
-              else
-                ps = "";
-              endif
-            else
-              ps = "";
-            endif
-
             if (mono)
               colorspec = "";
             else
               colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
                                    round (255*color));
             endif
-            withclause{data_idx} = sprintf ("with %s %s %s %s %s %s",
-                                            style, lw, pt, lt, ps, 
-                                            colorspec);
 
+             sidx = 1;
+             if (isempty (lt))
+               style = "";
+             else
+               style = "lines";
+             endif
+             tmpwith = {};
+
+             facesame = true;
+             if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor") 
+                && !strncmp (obj.markerfacecolor, "none", 4))
+               if (strncmp (obj.markerfacecolor, "auto", 4)
+                  || ! isnumeric (obj.markerfacecolor) 
+                  || (isnumeric (obj.markerfacecolor) 
+                      && isequal (color, obj.markerfacecolor)))
+                style = strcat (style, "points");
+                if (isfield (obj, "markersize"))
+                  if (length (mdat) == nc)
+                    m = mdat(i);
+                  else
+                    m = mdat;
+                  endif
+                  ps = sprintf("pointsize %f", m / 3);
+                 else
+                   ps = "";
+                endif
+
+                tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s",
+                                         style, lw, pt2, lt, ps, 
+                                         colorspec);
+               else
+                facesame = false;
+                if (! isempty (style)) 
+                  tmpwith{sidx} = sprintf ("with %s %s %s %s",
+                                           style, lw, lt, 
+                                           colorspec);
+                  sidx ++;
+                endif
+                if (isnumeric (obj.markerfacecolor) && ! mono)
+                  colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                       round (255*obj.markerfacecolor));
+                endif
+                style = "points";
+                if (isfield (obj, "markersize"))
+                  if (length (mdat) == nc)
+                    m = mdat(i);
+                  else
+                    m = mdat;
+                  endif
+                  ps = sprintf("pointsize %f", m / 3);
+                 else
+                   ps = "";
+                endif
+                tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s",
+                                         style, lw, pt2, lt, ps, 
+                                         colorspec);
+               endif
+             endif
+
+             if (isfield (obj, "markeredgecolor") 
+                && !strncmp (obj.markeredgecolor, "none", 4))
+               if (facesame && (strncmp (obj.markeredgecolor, "auto", 4)
+                               || ! isnumeric (obj.markeredgecolor) 
+                               || (isnumeric (obj.markeredgecolor) 
+                                   && isequal (color, obj.markeredgecolor))))
+                if (! isequal (pt, pt2) && sidx == 1 
+                     && ((length (style) == 5 
+                         && strncmp (style, "lines", 5)) 
+                         || isempty (style)))
+                  style = strcat (style, "points");
+                  if (isfield (obj, "markersize"))
+                    if (length (mdat) == nc)
+                      m = mdat(i);
+                    else
+                      m = mdat;
+                    endif
+                    ps = sprintf("pointsize %f", m / 3);
+                   else
+                     ps = "";
+                  endif
+                  tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s",
+                                           style, lw, pt, lt, ps, 
+                                           colorspec);
+                endif
+               else
+                if (!isempty (style))  
+                   if (isempty (tmpwith{sidx}))
+                    tmpwith{sidx} = sprintf ("with %s %s %s %s",
+                                             style, lw, lt, 
+                                             colorspec);
+                   endif
+                  sidx ++;
+                endif
+                if (! mono)
+                  if (strncmp (obj.markeredgecolor, "auto", 4))
+                    colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                         round (255*color));
+                  elseif (isnumeric (obj.markeredgecolor) && ! mono)
+                    colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
+                                         round (255*obj.markeredgecolor));
+                  endif
+                endif
+                style = "points";
+                if (isfield (obj, "markersize"))
+                  if (length (mdat) == nc)
+                    m = mdat(i);
+                  else
+                    m = mdat;
+                  endif
+                  ps = sprintf("pointsize %f", m / 3);
+                 else
+                   ps = "";
+                endif
+                tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s",
+                                         style, lw, pt, lt, ps, 
+                                         colorspec);
+               endif
+             endif
+
+             if (isempty (tmpwith))
+               withclause{data_idx} = sprintf ("with %s %s %s %s %s",
+                                               style, lw, pt, lt, 
+                                               colorspec);
+             else
+              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)], ...
@@ -882,6 +993,29 @@
               endif
               usingclause{data_idx} = sprintf ("record=%d using ($1):($2)", 
columns (data{data_idx}));
             endif
+
+            if (length (tmpwith) > 1)
+              data_idx++;
+              is_image_data(data_idx) = is_image_data(data_idx - 1); 
+              parametric(data_idx) = parametric(data_idx - 1);
+              have_cdata(data_idx) = have_cdata(data_idx - 1);
+              have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
+              titlespec{data_idx} = "title \"\"";
+              usingclause{data_idx} = usingclause{data_idx - 1};
+              data{data_idx} = data{data_idx - 1};
+              withclause{data_idx} = tmpwith{2};
+            endif
+            if (length (tmpwith) > 2)
+              data_idx++;
+              is_image_data(data_idx) = is_image_data(data_idx - 1); 
+              parametric(data_idx) = parametric(data_idx - 1);
+              have_cdata(data_idx) = have_cdata(data_idx - 1);
+              have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
+              titlespec{data_idx} = "title \"\"";
+              usingclause{data_idx} = usingclause{data_idx - 1};
+              data{data_idx} = data{data_idx - 1};
+              withclause{data_idx} = tmpwith{3};
+            endif
           endif
         endfor
 
diff --git a/src/ChangeLog b/src/ChangeLog
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2010-01-12  David Bateman  <address@hidden>
+
+       * graphics.h.in (patch::properties): Add "flat" value to
+       markeredgecolor and  markerfacecolor properties.
+
 2010-01-12  Jaroslav Hajek  <address@hidden>
 
        * ov-base.h (builtin_type_t): New enum constants: btyp_cell,
diff --git a/src/graphics.h.in b/src/graphics.h.in
--- a/src/graphics.h.in
+++ b/src/graphics.h.in
@@ -3299,8 +3299,8 @@
       radio_property linestyle , "{-}|--|:|-.|none"
       double_property linewidth , 0.5
       radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h"
-      color_property markeredgecolor , "{auto}|none"
-      color_property markerfacecolor , "auto|{none}"
+      color_property markeredgecolor , "{auto}|none|flat"
+      color_property markerfacecolor , "auto|{none}|flat"
       double_property markersize , 6
       string_property keylabel , ""
       radio_property interpreter , "{tex}|none|latex"

reply via email to

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