bugGNU Octave - Bugs: bug #47149, line ([x1, x2]', [y1, y2]) is one...


bug #47149: line ([x1, x2]', [y1, y2]) is one line in Matlab but not Octave

Submitted by:  Lachlan Andrew <lachlan>
Submitted on:  Mon 15 Feb 2016 02:12:16 AM UTC  
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Lachlan Open/Closed:  Closed
Release:  dev Operating System:  GNU/Linux

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Wed 12 Dec 2018 11:10:10 PM UTC, comment #11: 

I completely rewrote the underlying code for _line_ to resolve bug #39036.  It also resolves this bug report.  Closing as fixed.

Rik <rik5>
Project Administrator
Fri 26 Aug 2016 08:44:17 AM UTC, comment #10: 

Are you still planning to work on this?

I've regularly applied the cset but I've recently discovered that it gives rise to FAILs in copyobj.m and hgsave.m.
Maybe it is just the way the tests are set up, but I have no time for looking into it for a while.

Philip Nienhuis <philipnienhuis>
Project Member
Tue 03 May 2016 08:20:19 AM UTC, comment #9: 

I just noticed that there is overlap between this bug report and bug #39036.  I'm adding a link, and will look into merging the patches.

Lachlan Andrew <lachlan>
Tue 05 Apr 2016 09:06:01 PM UTC, comment #8: 

I finally got round to testing this patch the last days. AFAICS it works OK.

Can this be pushed?

Philip Nienhuis <philipnienhuis>
Project Member
Fri 19 Feb 2016 11:28:42 PM UTC, comment #7: 

The attached patch supports all of the forms that Philip proposed, and leaves the properties of the lines as close to Matlab compatible as I could manage.

(file #36402)

Lachlan Andrew <lachlan>
Fri 19 Feb 2016 12:22:59 AM UTC, comment #6: 

Good point, jwe.  I was totally forgetting that it is possible to access the data again.

The reason I wasn't getting any line was that I was drawing vertical lines,

  line ([x1, x1]', [y1, y2])

and so each line was reduced to a single point.

Fortunately, Matlab gives

>> h = line ([1,2]', [3,4])
h =
>> get (h, {'xdata', 'ydata'})
ans =
    [1x2 double]    [1x2 double]

so it seems we can just transpose the data -- much better than having to modify some subset of graphics toolkits to reinterpret the data.

Similar to your last example, Octave gives a diagonal line for the one-shot command

 line ('xdata', [1, 2]', 'ydata', [3, 4]);

Thanks for all your guidance.

Lachlan Andrew <lachlan>
Thu 18 Feb 2016 05:34:32 AM UTC, comment #5: 

I see this behavior:

octave:1> h = line ([1,2]',[3,4])
h =


octave:2> get (h(1), {'xdata', 'ydata'})
ans =
  [1,1] =

     1   2

  [1,2] =

     3   3

octave:3> get (h(2), {'xdata', 'ydata'})
ans =
  [1,1] =

     1   2

  [1,2] =

     4   4


Then if I change the axis limits, the horizontal lines appear in the plot window.

So it looks like the problem is that line is doing something similar to broadcasting and creating two line objects instead of recognizing that there are two vectors of the same length.

When fixing this, it's important to make sure that the x and y data stored in the line object are oriented in a Matlab-compatible way.  Do they retain their original orientation, or is one transposed so they are both row (or column) vectors?

I see that the following appears to work, so I think the bug is just in making line recognize the case of vectors with different orientations.

h = line;
set (h, 'xdata', [1,2]', 'ydata', [3,4])

John W. Eaton <jwe>
Project Administrator
Thu 18 Feb 2016 02:20:40 AM UTC, comment #4: 

Thanks, Philip.  I'll have a go at coding that somewhat efficiently.

Note that the bug report was about the low-level "line" command rather than high-level "plot" command.  I think that Octave's "plot" already handles these rotations, but "line" doesn't.  (I checked your examples in Matlab, and it handles line flexibly too.)  I just don't want to put too much additional checking into "line" because a "stem" command can call it  hundreds of times, last I checked.

Lachlan Andrew <lachlan>
Wed 17 Feb 2016 04:39:18 PM UTC, comment #3: 

Lachlan, in your title example the length of the vector matches. That is all that Matlab needs.

What works (in ML 2014a) is e.g. (by the absence of error messages),

>> a = rand (3, 5)
a =
    0.8147    0.9134    0.2785    0.9649    0.9572
    0.9058    0.6324    0.5469    0.1576    0.4854
    0.1270    0.0975    0.9575    0.9706    0.8003
>> b = [1 : 3]
b =
     1     2     3
>> plot (b, a)
>> plot (b, a')
>> plot (b', a')
>> plot (b', a)
>> plot (a, b)

(note that in the last example the plot is rotated 90 degrees relative to the previous examples).

But ML has limitations:

>> c = [1 : 3; 4: 6]
c =
     1     2     3
     4     5     6
>> plot (c, a)
Error using plot
Vectors must be the same lengths.
>> d = rand (3, 5, 2)
d(:,:,1) =
    0.1419    0.7922    0.0357    0.6787    0.3922
    0.4218    0.9595    0.8491    0.7577    0.6555
    0.9157    0.6557    0.9340    0.7431    0.1712
d(:,:,2) =
    0.7060    0.0462    0.6948    0.0344    0.7655
    0.0318    0.0971    0.3171    0.4387    0.7952
    0.2769    0.8235    0.9502    0.3816    0.1869
>> plot (b, d)
Error using plot
Data may not have more than 2 dimensions

...so one of the arguments to plot must be a vector, the other can be a matrix of which at least one dimension must have the same length as the vector argument.

AFAICS Matlab first tries to match dimensions/orientations as specified on the command line/instruction, and if it finds no match, tries rotating arguments until it finds common lengths, otherwise fails with an error message.

Philip Nienhuis <philipnienhuis>
Project Member
Tue 16 Feb 2016 10:41:41 PM UTC, comment #2: 

Thanks for checking, Philip.  In the example I gave, neither dimension matches, but Matlab still draws the line.  When I get to work, I'll check further.

Do we want to copy Matlab's forgiving behaviour exactly, partially or not at all?  I'm in favour of copying whatever is quick to check for.

Lachlan Andrew <lachlan>
Mon 15 Feb 2016 09:40:38 AM UTC, comment #1: 

Matlab is very forgiving even if one is a matrix. AFAICS Matlab only checks which dimensions of the input vectors/matrices match and then use that for plotting.

Philip Nienhuis <philipnienhuis>
Project Member
Mon 15 Feb 2016 02:12:16 AM UTC, original submission:  

If all X, Y and Z are vectors of the same length, Matlab doesn't seem to care whether they are row or column vectors.

Octave plots nothing if X is a column and Y is a row.

Lachlan Andrew <lachlan>


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

Attach Files:

Attached Files
file #36402:  bug_47149_line_x_y_transpose.cset added by lachlan (3KiB - application/octet-stream)
file #36339:  bug_line_x_y_transpose.cset added by lachlan (1KiB - application/octet-stream)


Depends on the following items

   bug dependencies.

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by philipnienhuis
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by lachlan (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-12 rik5 StatusIn Progress => Fixed
        Assigned tolachlan => None
        Open/ClosedOpen => Closed
    2016-05-14 lachlan StatusReady For Test => In Progress
    2016-05-03 lachlan Dependencies- => Depends on bugs #39036
    2016-04-17 philipnienhuis Carbon-Copy- => Added philipnienhuis
    2016-02-19 lachlan Attached File- => Added bug_47149_line_x_y_transpose.cset, #36402
        StatusIn Progress => Ready For Test
        Summaryline ([x1, x2]\', [y1, y2]) works in Matlab but not Octave => line ([x1, x2]', [y1, y2]) is one line in Matlab but not Octave
    2016-02-18 lachlan StatusPatch Submitted => In Progress
    2016-02-15 lachlan Attached File- => Added bug_line_x_y_transpose.cset, #36339

    Back to the top

    Powered by Savane 3.7