bugGNU Octave - Bugs: bug #46835, Error on modifying properties of a...

 
 

bug #46835: Error on modifying properties of a legend in plotyy

Submitter:  Konstantinos Poulios <logari81>
Submitted:  Wed 06 Jan 2016 10:33:35 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  rik5
Originator Name:  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

Wed 03 Jan 2018 10:03:19 AM UTC, comment #11: 

@Rik: Sorry for the xmas & new year's delay.  Awesome work, the legend works for me now!

The complicated scripts of comment #9 I created to check the original submission's problem, but thanks to your effort they are no longer "complicated" for Octave ;-)

Kai Torben Ohlhus <siko1056>
Group Member
Tue 26 Dec 2017 05:52:55 PM UTC, comment #10: 

@Kai: This is a very complicated script, and I wouldn't call plotyy twice on the same figure.  Instead, use the axes returned from the first call and continue plotting into each of those axes as necessary.


x = 1:3;
[hax,h1,h2]=plotyy(x,2:4,x,6:-1:4);
hold on
#[~,h3,h4]=plotyy(x,3:5,x,5:-1:3);  # not recommended
h3 = plot (hax(1), x, 3:5);
h4 = plot (hax(2), x, 5:-1:3);
h5=plot(hax(2),x,5:7);


But yes, it does reveal a known problem with the fact that the legend is re-created when the fontsize changes.  I checked in a change that appears to work here (http://hg.savannah.gnu.org/hgweb/octave/rev/359596cc55dd).


Rik <rik5>
Group administrator
Mon 25 Dec 2017 06:44:31 PM UTC, comment #9: 

Thank you for considering this item Rik.  It has been a while since I looked at it.  I uploaded four files, two scripts and the respective outputs (bug46835_comment9*).  To my understanding, the version A should work like described in the legend if this item was working properly.  This is still not the case after applying your patch or do I get something wrong?

(file #42728, file #42729,

Kai Torben Ohlhus <siko1056>
Group Member
Fri 22 Dec 2017 04:16:54 PM UTC, comment #8: 

I made a lot of improvements to plotyy and to legend in the last few days on the development branch.  The original example seems to work for me now.  If some one can confirm I will close this report.  Try a cset >= 436deae9f9ab from 2 days ago.

Rik <rik5>
Group administrator
Wed 30 Nov 2016 02:20:28 PM UTC, comment #7: 

In Octave 4.2.0, when calling legend() after plotyy(), the private function updatelegend() triggers an error when calling set(hax,"units",units) with units being a cellstr.

When modifying the code by adding a loop to index hax(k) and units{k} simultaneously then it works : set(hax(k),"units",units{k}) does not trigger an error.

The loop described above should requires to check first that units is a cell-array of strings...

Renaud GILLON <reginalduck>
Thu 17 Nov 2016 10:37:49 AM UTC, comment #6: 

This bug is still present in the current dev 4.3.0 (39f39eb4e476).

I filed task #14243 about rewriting legend.m

Pantxo Diribarne <pantxo>
Group Member
Wed 27 Jan 2016 01:22:12 PM UTC, comment #5: 

Finally I committed the partial fix to avoid the hard error. But the misbehavior is still present and needs deeper investigation.

http://hg.savannah.gnu.org/hgweb/octave/rev/6f6eae08836f

Kai Torben Ohlhus <siko1056>
Group Member
Fri 08 Jan 2016 08:11:24 PM UTC, comment #4: 

Yes, I see your point. For what I figured out is that the handles are assigned to the y-axis:

{h1,h3} and {h2,h4,h5}

which is the order printed by default by

>> hl = legend('l1','l2','l3','l4','l5');


If you provide the order of the handles like in comment #3, everything is fine.

Now comes the trouble: set (libinterp/corefcn/graphics.cc) triggers the legend function again, but ignoring any previous legend order, using the default order mentioned above. Other way round: creating a fake legend, font resize and create another legend results in using the default font. Annoying!

Seems like way more work...

Anyway the fix of comment #1 improves the situation a little.

Kai Torben Ohlhus <siko1056>
Group Member
Fri 08 Jan 2016 03:05:12 PM UTC, comment #3: 

Just for documenting my claim. In the attached file you can see the output of octave after applying Kai's fix.

The correct color order in the legend would be as defined in my original report: red, green, blue, magenta, cyan

So it is the lines that are garbled, not the strings.

Unfortunately the fix of my originally post doesn't work either. It results in "red, blue, green, magenta, cyan", even if it is called with line handles:

>> hl = legend([h1,h2,h3,h4,h5],{'l1','l2','l3','l4','l5'});





Konstantinos Poulios <logari81>
Fri 08 Jan 2016 01:08:44 PM UTC, comment #2: 

Be careful, that was the first thing that I tried also. The cell2mat fixes the crash but there is still not correct behavior. For some reason the legend strings get reordered. Before you commit a change, please take a look at my fix, attached in the first report. My fix still didn't solve the problem 100% but at least it works when the legend is defined with line handles like:

legend([h1,h2,h3], {'text1','text2','text3'})

while the cell2mat fix as far as I remember it didn't.

Konstantinos Poulios <logari81>
Fri 08 Jan 2016 12:21:43 PM UTC, comment #1: 

I can confirm this. The fix is quite simple, I soon prepare a patch:

>> edit _getlegenddata_


Replace line 32

kids = [get(ca, "children"){:}];

by

kids = cell2mat (get (ca, "children"));

Kai Torben Ohlhus <siko1056>
Group Member
Wed 06 Jan 2016 10:33:35 PM UTC, original submission:  


>> version

ans = 4.0.1-rc1

>> clf
>> [hax,h1,h2]=plotyy(1:3,2:4,1:3,6:-1:4);
>> hold on
>> [~,h3,h4]=plotyy(1:3,3:5,1:3,5:-1:3);
>> h5=plot(hax(2),1:3,5:7);
>> set(h1,'color','r')
>> set(h2,'color','g')
>> set(h3,'color','b')
>> set(h4,'color','m')
>> set(h5,'color','c')
>> hl = legend('l1','l2','l3','l4','l5');
>> set(hl,'fontsize',14)

error: horizontal dimensions mismatch (2x1 vs 3x1)
error: called from
    _getlegenddata_ at line 32 column 10
    legend>updatelegend at line 1080 column 17
error: octave_base_value::double_value (): wrong type argument '<unknown type>'
error: octave_base_value::convert_to_str_internal (): wrong type argument '<unknown type>'
error: octave_base_value::convert_to_str_internal (): wrong type argument '<unknown type>'
error: octave_base_value::convert_to_str_internal (): wrong type argument '<unknown type>'
error: octave_base_value::matrix_value(): wrong type argument '<unknown type>'
error: set: A(I,J): row index out of bounds; value 1 out of bound 0

Konstantinos Poulios <logari81>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #42728:  bug46835_comment9a.m added by siko1056 (334B - text/x-objcsrc)
file #42729:  bug46835_comment9b.m added by siko1056 (348B - text/x-objcsrc)
file #42730:  bug46835_comment9a.png added by siko1056 (53KiB - image/png)
file #42731:  bug46835_comment9b.png added by siko1056 (49KiB - image/png)
file #35948:  bug46835.png added by logari81 (38KiB - image/png)
file #35939:  __getlegenddata__.m added by logari81 (2KiB - text/x-objcsrc - Possible fix)

 

Depends on the following items: None found

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 reginalduck (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by logari81 (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 16 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-01-03 siko1056 Assigned tosiko1056 rik5
    2018-01-02 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2017-12-25 siko1056 Attached File- Added bug46835_comment9a.m, #42728
        Attached File- Added bug46835_comment9b.m, #42729
        Attached File- Added bug46835_comment9a.png, #42730
        Attached File- Added bug46835_comment9b.png, #42731
    2017-12-22 rik5 StatusConfirmed Ready For Test
    2016-01-27 siko1056 Item GroupSegfault, Bus Error, etc. Incorrect Result
        StatusIn Progress Confirmed
        Release4.0.1-rc1 dev
    2016-01-08 logari81 Attached File- Added bug46835.png, #35948
    2016-01-08 siko1056 StatusNone In Progress
        Assigned toNone siko1056
        Operating SystemGNU/Linux Any
    2016-01-06 logari81 Attached File- Added _getlegenddata_.m, #35939

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code