bugGNU Octave - Bugs: bug #34906, Compatibility difference with...

 
 

bug #34906: Compatibility difference with ticklabels, linestyleorder

Submitter:  Ben Abbott <bpabbott>
Submitted:  Sat 26 Nov 2011 05:50:30 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Ben Abbott Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 06 Sep 2013 12:07:12 AM UTC, comment #16: 

I checked in one more change to deal with converting linestyleorder into a row vector char matrix (http://hg.savannah.gnu.org/hgweb/octave/rev/50b2863d10a6).  Closing report.

Rik <rik5>
Group administrator
Wed 26 Jun 2013 11:13:08 PM UTC, comment #15: 

I checked in a changeset that fixes repetition and string trimming (http://hg.savannah.gnu.org/hgweb/octave/rev/359ac80ecb30).  The only thing I trim is spaces.  Matlab may be trimming other whitespace as well such as tab (\t) or newline (\n) or return (\r).  I doubt they trim the newline because then it would be difficult to have multi-line labels.  Someone can check what characters Matlab is trimming or we can just go with what we have here.

Ben, is the general behavior that when given a cell array vector that the return is always a column vector?  Is this true for numeric cell arrays as well as string cell arrays?  If so then that reshaping should be done more generally than just in the convert_ticklabel_string routine.

Similarly, do all arguments that accept strings split on the delimiter '|'?  What about something like title()?  Can you get a multi-line title with


title ('line1|line2');


I'm wondering if we only need to write one more routine to deal with linestyleorder or whether bigger changes have to be made.

Rik <rik5>
Group administrator
Wed 26 Jun 2013 10:06:16 PM UTC, comment #14: 

I pushed another changeset which deals with the a trailing delimeter in the ticklabel string ("abc|") (http://hg.savannah.gnu.org/hgweb/octave/rev/563f8f0a7e29).  It also makes use of an option to the charMatrix constructor to get rid of a for loop.

The repetition operation might take a bit more time.  I only just found out where the relevant code is gl_render.cc:render_ticktexts ().

Rik <rik5>
Group administrator
Tue 25 Jun 2013 05:21:46 PM UTC, comment #13: 

According to Matlab Online documentation, the specified labels are reused until all tick marks are set. (Is it OK to post links next time or will this violate Mathworks terms of use?)


set (gca, 'xticklabel', 'a'); assert (get (gca (), "xticklabel"), ['a']);
set (gca, 'xticklabel', 'a|'); assert (get (gca (), "xticklabel"), ['a'; ' ']);
set (gca, 'xticklabel', 'a|b'); assert (get (gca (), "xticklabel"), ['a'; 'b']);


For the first example all ticklabels will be named 'a'.
In the seconds case the labels are 'a', nothing, 'a', nothing and so on. (See picture)
The third example is basically the same as the second: 'a', 'b', 'a', 'b', ...

Attached two pictures (made by markuman(IRC/#octave)).


Stefan Mahr <dac922>
Tue 25 Jun 2013 04:40:06 PM UTC, comment #12: 

I've never had access to Matlab so I don't always know what I'm aiming for.

What is the desired behavior for the following?


plot (1:4);
set (gca, 'xticklabel', 'a');
set (gca, 'xticklabel', 'a|');
set (gca, 'xticklabel', 'a|b');


Is it always supposed to repeat the base element until it has enough tick values?

Rik <rik5>
Group administrator
Tue 25 Jun 2013 09:21:52 AM UTC, comment #11: 

Rik,

There's a reason why I did not use getline. It breaks this code:

set (gca (), "xticklabel", "a|");
xticklabel = get (gca (), "xticklabel");
assert (xticklabel, ["a";" "] );


> The behavior of xticklabels is getting much better, but there is
> still a problem with alignment of the labels.
> If you look at the plot you will notice that the labels for
> 1,2,3,4 are offset to the left from their tickmark.


This problem doesn't appear with gnuplot, only with fltk.

> It seems like a possible solution would be to change to a
> null-delimited character array such that the first label was
> '1\0\0\0\0'.


AFAIK, this would break matlab compatibility when doing
 get (gca (), "xticklabel");
 
IMHO, the font renderer has to trim the strings. Also, there's another problem with fltk frontend:


plot(1:4);
set (gca (), "xticklabel", "a");


The xticklabel only appears at the first position and is not repeated.


Stefan Mahr <dac922>
Mon 24 Jun 2013 11:38:06 PM UTC, comment #10: 

I checked in a changeset which makes Octave always return column vectors of cell strings for ticklabels (http://hg.savannah.gnu.org/hgweb/octave/rev/2ce1ddead134).

Rik <rik5>
Group administrator
Mon 24 Jun 2013 10:18:45 PM UTC, comment #9: 

The behavior of xticklabels is getting much better, but there is still a problem with alignment of the labels.

Sample code:


plot (1:4);
set (gca, 'xticklabel', '1|1.500|2|2.500|3|3.500|4')


If you look at the plot you will notice that the labels for 1,2,3,4 are offset to the left from their tickmark.  The problem is that we are splitting and converting the string to a character matrix where the fill character is a space.  Thus, the label '1' is really '1    ' to match the width of '1.500'.

When you pass a cell array of values this isn't a problem.

It seems like a possible solution would be to change to a null-delimited character array such that the first label was '1\0\0\0\0'.  Then in the font renderer code we could put in something to look only for a C string so that this would become '1' rather than a 5 character sequence.  Just an idea.

Rik <rik5>
Group administrator
Mon 24 Jun 2013 10:10:27 PM UTC, comment #8: 

I modified the code to use standard Octave coding conventions (http://hg.savannah.gnu.org/hgweb/octave/rev/969233a27bce).  We like to distinguish between indexing and function calls by using a space between the function name and the opening parenthesis.


x(idx)   # indexing
cos (x)  # function call


These rules are maintained in the C++ code as well.  I also added missing semicolons to the end of lines for %!test blocks.

Rik <rik5>
Group administrator
Tue 11 Jun 2013 03:03:02 PM UTC, comment #7: 

Yes, both "make check" and "rundemos plot" show no problems related to xticklabel.

Stefan Mahr <dac922>
Tue 11 Jun 2013 01:40:52 PM UTC, comment #6: 

I ran "make check" and "rundemos plot".  I didn't see any regressions, but will wait for a confirmation.  I'm attached a Stephan's changeset with some tests added.

(file #28293)

Ben Abbott <bpabbott>
Group Member
Tue 11 Jun 2013 01:14:19 PM UTC, comment #5: 

Stefan,

Have you verified there are no problems with "rundemos plot", and "make check"?


Ben Abbott <bpabbott>
Group Member
Tue 11 Jun 2013 11:46:07 AM UTC, comment #4: 

With new attached patch the behaviour is now similar to matlab.


set (gca, 'xticklabel', [0, 0.2, 0.4, 0.6, 0.8, 1])
xticklabel1 = get (gca, 'xticklabel');
set (gca, 'xticklabel', '0|0.2|0.4|0.6|0.8|1')
xticklabel2 = get (gca, 'xticklabel');
set (gca, 'xticklabel', ['0 '; '0.2'; '0.4'; '0.6'; '0.8'; '1 '])
xticklabel3 = get (gca, 'xticklabel');
set (gca, 'xticklabel', {'0', '0.2', '0.4', '0.6', '0.8', '1'})
xticklabel4 = get (gca, 'xticklabel');
whos xticklabel1 xticklabel2 xticklabel3 xticklabel4
Variables in the current scope:

   Attr Name             Size                     Bytes  Class
   ==== ====             ====                     =====  =====
        xticklabel1      6x3                         18  char
        xticklabel2      6x3                         18  char
        xticklabel3      6x3                         18  char
        xticklabel4      1x6                         14  cell



(file #28290)

Stefan Mahr <dac922>
Thu 06 Jun 2013 06:51:18 PM UTC, comment #3: 

attached patch partially solves the issue, but only for xticklabel at the moment.

i do not like to use feval for calling num2str and strsplit, maybe someone has a better solution.

if using '|' as delimiter when setting xticklabel, 'get' returns a cell array instead of a char array, so it's not fully compatible to matlab yet.


(file #28273)

Anonymous
Wed 13 Mar 2013 11:34:43 PM UTC, comment #2: 

I'm not too concerned with the char vs. cellstr.  But Octave has zero support for a string that uses '|' as a delimiter.  Instead it treats it as a single label which gets put at the first xtick position.


Rik <rik5>
Group administrator
Sun 27 Nov 2011 12:53:17 AM UTC, comment #1: 

I took a look at how linestyleorder behaves under matlab.


set (gca, 'linestyleorder', '-|--|-.|:')
linestyleorder1 = get (gca, 'linestyleorder');
set (gca, 'linestyleorder', ['- ';'--';'-.';': '])
linestyleorder2 = get (gca, 'linestyleorder');
set (gca, 'linestyleorder', {'-','--','-.',': '})
linestyleorder3 = get (gca, 'linestyleorder');
whos linestyleorder1 linestyleorder2 linestyleorder3

  Name                 Size            Bytes  Class    Attributes

  linestyleorder1      4x2                16  char
  linestyleorder2      4x2                16  char
  linestyleorder3      4x1               462  cell


ML's behavior looks consistent to me.

Ben Abbott <bpabbott>
Group Member
Sat 26 Nov 2011 05:50:30 PM UTC, original submission:  

There is a subtle incompatibility in how ML and Octave handle ticklabels. Below I use xticklabels to demonstrate, but the problem exists for x, y, z ticklabels.


set (gca, 'xticklabel', [0, 0.2, 0.4, 0.6, 0.8, 1]
xticklabel1 = get (gca, 'xticklabel');
set (gca, 'xticklabel', '0|0.2|0.4|0.6|0.8|1')
xticklabel2 = get (gca, 'xticklabel');
set (gca, 'xticklabel', ['0 '; '0.2'; '0.4'; '0.6'; '0.8'; '1 '])
xticklabel3 = get (gca, 'xticklabel');
set (gca, 'xticklabel', {'0', '0.2', '0.4', '0.6', '0.8', '1'})
xticklabel4 = get (gca, 'xticklabel');
whos xticklabel1 xticklabel2 xticklabel3 xticklabel4


ML uses the 3rd variant for the default xticklabel values., and Octave uses the 4th (1x6 cellstr)

Each set() statement works in both Octave and ML. However, the resulting values returned by the get() are different.

Octave returns ...


Variables in the current scope:

   Attr Name             Size                     Bytes  Class
   ==== ====             ====                     =====  =====
        xticklabel1      1x6                         48  double
        xticklabel2      1x19                        19  char
        xticklabel3      6x3                         18  char
        xticklabel4      1x6                         14  cell


And ML ...


  Name             Size            Bytes  Class    Attributes

  xticklabel1      6x3                36  char
  xticklabel2      6x3                36  char
  xticklabel3      6x3                36  char
  xticklabel4      6x1               700  cell


I see three differences.

(1) The default xticklabel values for ML are char, and are cell (cellstr) for Octave.

(2) ML converts the xticklabel with class double or char with "|" used as a delimiter to a char array. Octave returns the same class and format as was passed to set().

(3) ML converts a cellstr column vector (1xN) to a row vector (Nx1).

Ben Abbott <bpabbott>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #28412:  matlab_xticklabel.png added by dac922 (10KiB - image/png)
file #28293:  changeset.patch added by bpabbott (5KiB - application/octet-stream - Stephan's changeset with some tests added.)
file #28290:  ticklabel.patch added by dac922 (4KiB - text/x-patch)
file #28273:  ticklabel.patch added by None (2KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dac922 (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by bpabbott (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 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-09-06 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2013-06-26 rik5 StatusNone In Progress
    2013-06-25 dac922 Attached File- Added matlab_xticklabel.png, #28412
        Attached File- Added matlab_xticklabel_a_empty.png, #28413
    2013-06-11 bpabbott Attached File- Added changeset.patch, #28293
    2013-06-11 dac922 Carbon-CopyRemoved -email is unavailable- -
    2013-06-11 dac922 Attached File- Added ticklabel.patch, #28290
        Carbon-Copy- Added -email is unavailable-
    2013-06-06 None Attached File- Added ticklabel.patch, #28273
    2011-11-27 bpabbott SummaryCompatibility difference with ticklabels Compatibility difference with ticklabels, linestyleorder
    2011-11-26 bpabbott SummaryCompatibility difference Compatibility difference with ticklabels

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code