bugGNU Octave - Bugs: bug #46484, datetick does not...

 
 

bug #46484: datetick does not "keeplimits"

Submitter:  None
Submitted:  Fri 20 Nov 2015 07:43:49 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Lars K. Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 31 Jan 2016 08:27:13 PM UTC, comment #4: 

Pushed here:
http://hg.savannah.gnu.org/hgweb/octave/rev/446bab5da2f7

Sorry for the delay, got a bit distracted.
Thanks for the contribution.

Closing report

Philip Nienhuis <philipnienhuis>
Group Member
Sat 12 Dec 2015 07:00:17 PM UTC, comment #3: 

Thanks, that's me.

Lars Kindermann <larskindermann>
Sat 12 Dec 2015 05:02:30 PM UTC, comment #2: 

Your patch looks to work OK.

Would you like to be credited? if so could you supply your full name, please?

Philip Nienhuis <philipnienhuis>
Group Member
Sat 12 Dec 2015 02:04:06 PM UTC, comment #1: 



The datetick.m included in Octave always calculates tick positions from min and max of the data, while it should do so from min and max of the axis limit when the "keeplimits" option is given.

This means setting a new "xlim" followed by "datetick x keeplimits" will not provide meaningful tick positions.

This is a bug in Octave, Matlab does it right.

Why this is important:

There are several third party tools which provide zoom- and pan-able date-axes like "datetickx" or "dynamicDateticks". They will not work with the current datetick.m, neither any attempt to provide own scalable date axes.

The attached patch fixes it, could somebody please include it in the source?

Anonymous
Fri 20 Nov 2015 07:43:49 PM UTC, original submission:  

When datetick() is called with the "keeplimits" argument it should conserve the xlim resp. ylim property of the axis. That is the intended behavior and also what matlab does. At the moment, however, datetick.m always recalculates the limits based on the data. As a result it is not possible to reapply date labels after zooming in either from the gui or calling the xlim() or ylim() function:


t0=datenum('2015-01-01');
t=t0:1/1440:t0+30; %one month
x=sin(2*pi*(t-t0));
plot(t,x)
datetick x
disp "press enter to show one week only!"
pause
xlim([t0 t0+7]);
disp "press enter to apply datetick again!"
pause
datetick x keeplimits
%this will rescale to full data limits


This patch will fix it:


diff -r a5949b3d2332 scripts/plot/appearance/datetick.m
--- a/scripts/plot/appearance/datetick.m        Thu Nov 19 14:39:04 2015 -0800
+++ b/scripts/plot/appearance/datetick.m        Fri Nov 20 19:51:30 2015 +0100
@@ -144,18 +144,24 @@
   else
     ## Need to do our own axis tick position calculation as
     ## year, etc, don't fallback on nice datenum values.
-    objs = findall (gca ());
-    xmax = NaN;
-    xmin = NaN;
-    for i = 1 : length (objs)
-      fld = get (objs (i));
-      if (isfield (fld, [ax "data"]))
-        xdata = getfield (fld, [ax "data"])(:);
-        xmin = min (xmin, min (xdata));
-        xmax = max (xmax, max (xdata));
-      endif
-    endfor
-
+    if (keeplimits)
+      limits=get (gca (), [ax "lim"]);
+      xmin=limits(1);
+      xmax=limits(2);
+    else
+      objs = findall (gca ());
+      xmax = NaN;
+      xmin = NaN;
+      for i = 1 : length (objs)
+        fld = get (objs (i));
+        if (isfield (fld, [ax "data"]))
+          xdata = getfield (fld, [ax "data"])(:);
+          xmin = min (xmin, min (xdata));
+          xmax = max (xmax, max (xdata));
+        endif
+      endfor
+    endif
+
     if (isnan (xmin) || isnan (xmax))
       xmin = 0;
       xmax = 1;



Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by larskindermann (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-01-31 philipnienhuis StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code