bugGNU Octave - Bugs: bug #30461, legend should work for lines with...

 
 

bug #30461: legend should work for lines with different parents

Submitter:  Ben Abbott <bpabbott>
Submitted:  Fri 16 Jul 2010 11:21:51 AM UTC
   
 
Category:  Interpreter Severity:  1 - Wish
Priority:  1 - Later Item Group:  Feature Request
Status:  Fixed Assigned to:  dbateman
Originator Name:  bpabbott Open/Closed:  * Closed
Release:  * dev Operating System:  * Mac OS
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 08 Nov 2010 03:23:37 PM UTC, comment #25: 

My mistake. This was related to one of my changesets. I've pushed a change.

http://hg.savannah.gnu.org/hgweb/octave/rev/83d268af65cb


Ben Abbott <bpabbott>
Group Member
Mon 08 Nov 2010 09:26:25 AM UTC, comment #24: 

David, I'm seeing a problem with the plotyy demo.


plotyy example 1:
 clf
 x = 0:0.1:2*pi;
 y1 = sin (x);
 y2 = exp (x - 1);
 ax = plotyy (x, y1, x - 1, y2, @plot, @semilogy);
 xlabel ("X");
 ylabel (ax(1), "Axis 1");
 ylabel (ax(2), "Axis 2");
 axes (ax(1))
 text (0.5, 0.5, "Left Axis",
       "color", [0 0 1], "horizontalalignment", "center")
 axes (ax(2))
 text (4.5, 80, "Right Axis",
       "color", [0 0.5 0], "horizontalalignment", "center")

error: structure has no member `ydata'
error: evaluating argument list element number 1
error: invalid empty index list


I haven't looked at the detail, but I don't see this error if I type these commands, but do if I run the demo.

So this may not be related, to you (or other recent changes to the m-files) but I thought it best to check with you before posting to the list.

Ben Abbott <bpabbott>
Group Member
Sun 07 Nov 2010 09:41:31 PM UTC, comment #23: 

I just committed a changeset

http://hg.savannah.gnu.org/hgweb/octave/rev/9f080d23396f

that adds the fake axis to the gnuplot figures to handle the multi-parented case as discussed in comment #21. The fake axis is only added in the case that the legend is multi-parented and if it isn't the key of the existing plot is used for the legend. In this manner the "flickering movie" bug in #31522 will only be seen if multiple axes are in fact really used.

Note that there is an existing issue with the gnuplot backend and legends, that is in a case like


close all;
x=0:0.1:10;
[ax,h1,h2] = plotyy(x, sin(x), x, cos(x));
[h,ho,hp] = legend('sin(x)','cos(x)');
set (h1,"markerfacecolor", [1,0,0],"markeredgecolor", [0,1,0],"marker","o")


Where the line color and marker colors are different, the gnuplot backend only draws the line in the key. This is because gnuplot can't handle a line with different colors for the line and marker in a single line. I don't think there is anything that can be done about this. However, the above works fine with the FLTK backend.

I consider this feature request fully addressed with this commit and I'm closing this report.

D.

David Bateman <dbateman>
Group Member
Wed 03 Nov 2010 08:32:41 AM UTC, comment #22: 

opps ... my bad. I didn't not the "yy". I was just doing a simple plot.

Ben Abbott <bpabbott>
Group Member
Wed 03 Nov 2010 08:15:49 AM UTC, comment #21: 

It should work fine for the FLTK backend, but I'm surprised it works for Ben for the gnuplot backend. I've been meaning to get back to this to fix it properly for the gnuplot backend.

What has currently been done, is that the legend is now a separate axis in the frontend, and the FLTK code treats it as such. However as there is no way to get the gnuplot backend to tell us the text extents of the labels, the gnuplot backend replaces this separate axis with a legend on one of the two plotyy axes and so one of the legend keys can't be drawn.

What I'm thinking about doing for the gnuplot backend is to create a third axis with invisible axis, ticks, etc. Plot all of the lines used in the legend in this third axis, Set the axis limits such they are off screen and then get the axis to plot the legend. In this manner it should be possible to get the gnuplot backend to plot legends with axes with different parents

D.

David Bateman <dbateman>
Group Member
Wed 03 Nov 2010 07:46:35 AM UTC, comment #20: 

The my tip is ...


changeset:   11182:cb9c475b335f
tag:         tip
user:        John W. Eaton <jwe@octave.org>
date:        Wed Nov 03 03:37:59 2010 -0400
summary:     Added tag ss-3-3-53 for changeset 3cbc0d77db48


For me, both gnuplot and fltk produce the correct result.

Might it be something that depends  upon the version of gnuplot? I'm running gnuplot 4.4.

Ben Abbott <bpabbott>
Group Member
Wed 03 Nov 2010 02:43:30 AM UTC, comment #19: 

Are legends working for plotyy?  I read through the comments and it seems as if there have been a number of patches committed.  But I just tried the original code,


x = 0:0.1:10;
plotyy (x, sin (x), x, cos (x))
legend ("sin(x)" , "cos{x)")


and it still puts only one label up.  This was with a recent dev tip (2010-11-02).

Rik <rik5>
Group administrator
Mon 20 Sep 2010 12:59:57 AM UTC, comment #18: 

I've pushed the change for gnuplot/activepositionproperty

Ben Abbott <bpabbott>
Group Member
Mon 20 Sep 2010 12:30:51 AM UTC, comment #17: 

(I think) I found the problem with the axis demo, and committed a fix

    http://hg.savannah.gnu.org/hgweb/octave/rev/98a31b352aab

Ben Abbott <bpabbott>
Group Member
Sun 19 Sep 2010 11:32:53 PM UTC, comment #16: 

I tried running the demos and found a problem with suplots. Try ...

    demo ("axis", 4)

I don't know the cause, but will delay pushing other changes until this is fixed.

Any idea?

Ben Abbott <bpabbott>
Group Member
Sun 19 Sep 2010 09:25:06 PM UTC, comment #15: 

Any object that can have a legend entry should have a "displayname"

D.

David Bateman <dbateman>
Group Member
Sun 19 Sep 2010 08:30:09 PM UTC, comment #14: 

Should both patch and surface objects have a "displayname" property?

Ben Abbott <bpabbott>
Group Member
Sun 19 Sep 2010 08:23:27 PM UTC, comment #13: 

Commit your patch here or even your original code if it addresses the legend outside the axis problem. As long as we are using gnuplot for the legends, the original reason to remove it has gone away

D.

David Bateman <dbateman>
Group Member
Sun 19 Sep 2010 07:56:51 PM UTC, comment #12: 

Regarding "I see no reason not to recommit it", you're speaking of my proposed activepositionproperty changeset, correct?

I'll push that today (after I do a bit more checking).

When I have time I'll look at a fix for demos 10 & 11

Ben Abbott <bpabbott>
Group Member
Sun 19 Sep 2010 07:38:05 PM UTC, comment #11: 

Ben,

The legend code I wrote uses position internally for all its calculations as typically the legend is placed just inside the axis. I suppose it could use outerposition if the legend is outside the axis, though using outerposition if the legend is inside the axis would only work if the function graphics.cc void axes::properties::sync_positions (void)) synced position and outerpositions correctly. The code to do this is currently deactivated as the text extents of the labels, etc weren't taken into account.

The fact is the text extents with gnuplot can probably never be taken into account as we can't get gnuplot to tell us the text extents, and in any case they'll be different for each terminal type which will play havoc with objects that are placed on a screen terminal and then printed to a different terminal. So as far as I can see gnuplot can never have the position and outerposition code synced.

That being said, as we have to use the gnuplot legend code, again because gnuplot doesn't give the text extents, the original reason to get rid of your outerposition code has gone away, so I see no reason not to recommit it.

I'm not sure I'll have time for a couple of days to look at demos 10 and 11, so feel free to find the solution before then ;-) .. If not I'll look at it later.

Cheers
David


David Bateman <dbateman>
Group Member
Sat 18 Sep 2010 09:55:02 PM UTC, comment #10: 

I noticed a minor problem with the legend demos 10 and 11.

I've attached a changeset that implements the behavior I mentioned in my prior comment. With this the legend is able to render outside the plot box, but the position property is ignored for gnuplot when the outerposition is active.

With this changeset all demos run, but 10, and 11 don't show a legend.

(file #21489)

Ben Abbott <bpabbott>
Group Member
Sat 18 Sep 2010 09:03:55 PM UTC, comment #9: 

Regarding placing the key outside the plot box, there may be other solutions, but the one I know of was implemented in, now reverted, activepositionproperty changeset.

    http://hg.savannah.gnu.org/hgweb/octave/rev/9c0b366583cb

If we add that change back, then when "outerposition" is active it will always refer to the bbox of the axes and its labels. While that is not consistent with Matlab, I find it conceptually attractive from user perspective.

If that sounds like a reasonable compromise I can try putting a new patch together. The functions axis.m, and colorbar.m will need to treat the gnuplot backend in a special manner, but the changes are fairly trivial.

Ben Abbott <bpabbott>
Group Member
Sat 18 Sep 2010 08:32:13 PM UTC, comment #8: 

Well after a bit of testing of my legend code with the gnuplot backend and the terminals wxt, x11 and eps and using a number of different fonts it became evident that although the text extents calculation is ok for the wxt with my default font, its pretty bad in most other cases and there is no easy fudge to get the text extents code working with gnuplot.

The next choice is to keep the new fltk compatible legend code, but ignore the legend axes in the gnuplot backend while recovering the information for use with the gnuplot legend code. I have this working now with two issues

- The first is this bug report. Yes I have fixed this for the fltk backend, but the gnuplot "set key" code doesn't allow elements of the key to be taken from two different plots. My solution for this is going to be that I'll add a line to the figure but outside the axes so that it is not visible, and then I'll have an invisible line that I can add the key to.

- My second issue is that the gnuplot code positions the axes with code like

set origin 0.13, 0.149823076082663;
set size noratio 0.775, 0.775176923917337;

and this plays havoc the "set key outside" option of gnuplot. That is the axis size is modified by the "set key outside" option, but the  key remains inside the  axis. I don't see a good way of fixing this.

As this code doesn't seem to break anything, I can fix the first issue with an incremental fix, it adds support for fltk legends (addressing this bug in that case) and address the bug #29348 I applied my changeset in

http://hg.savannah.gnu.org/hgweb/octave/rev/e81914f3921f

Ben do you have any ideas of how to treat the second issue?

D.

David Bateman <dbateman>
Group Member
Sat 04 Sep 2010 02:18:16 PM UTC, comment #7: 

I wrote a short script to see how Matlab handles subplots with the same position. Matlab does not detect that some axes have the same position.

The script also tests if the legend command is able to accept both the axes handle as well as the handles for the line/patch/surface/etc objects, and it does.

I've attached the script and the resulting pdf.



(file #21386, file #21387)

Ben Abbott <bpabbott>
Group Member
Sat 04 Sep 2010 07:40:58 AM UTC, comment #6: 

Good question. I don't have access to matlab, so how are subplots handled?

What I'd think would be reasonable is if no axis handle is given to the legend function, all of the axes with the same position and outerposition values as the current axis will be grouped together in a single legend.

D.

David Bateman <dbateman>
Group Member
Fri 03 Sep 2010 08:54:33 PM UTC, comment #5: 

How would subplots be handled?

Ben Abbott <bpabbott>
Group Member
Fri 03 Sep 2010 08:39:37 PM UTC, comment #4: 

Frankly I don't think we have to implement the undocumented behavior of matlab knowing that they can change it whenever they like without warning. I'd say we should get the documented behavior right and forget the rest. I thought of having "legend" without an argument just treat all of the child axes of the current figure rather than the current axes, and this seems to me a relatively simple means of getting the same behavior.

Cheer
David

David Bateman <dbateman>
Group Member
Fri 03 Sep 2010 12:00:02 PM UTC, comment #3: 

I'm not sure exactly what Matlab is doing. But there are some hints in the axes properties and appdata.

>> plot (1:10)
>> legend ('hello world')
>> getappdata (hax(1))


ans =

        LegendTempText: 177.01
        MWBYPASS_title: {[1x1 function_handle]}
       MWBYPASS_xlabel: {[1x1 function_handle]}
       MWBYPASS_ylabel: {[1x1 function_handle]}
       MWBYPASS_zlabel: {[1x1 function_handle]}
         NonDataObject: []
    PostDeserializeFcn: @legendpostdeserialize
         LegendOldSize: [66 16.8]

>> getappdata (hax(2))


ans =

             PlotColorIndex: 2
         PlotLineStyleIndex: 1
         LegendColorbarText: [219.01 220.01]
    LegendColorbarInnerList: [1x1 scribe.legend]
    LegendColorbarOuterList: []
                   inLayout: []
      LegendComputePosCache: [0.13 0.11 0.775 0.815]
           LegendPeerHandle: 176.01

>> setdiff(fieldnames(get(hax(1))),fieldnames(get(hax(2)))


ans =

    'EdgeColor'
    'Interpreter'
    'Location'
    'Orientation'
    'String'
    'TextColor'

I can do some experiments if you have some suggestions.

Ben Abbott <bpabbott>
Group Member
Fri 03 Sep 2010 05:21:39 AM UTC, comment #2: 

Sure. Though given that legend works in this way with plotyy it looks to me like matlabs implementation of legend is workings with the child axes of the current figure rather than the current axis by default. This isn't how I thought it worked.

D.

David Bateman <dbateman>
Group Member
Fri 03 Sep 2010 01:22:39 AM UTC, comment #1: 

David, ok to assign this to you?

Ben Abbott <bpabbott>
Group Member
Fri 16 Jul 2010 11:21:51 AM UTC, original submission:  

The plotyy command uses two different axes to produce the impression of two y-axes. Using the legend command only labels the single line corresponding to the current axes (the 2nd is not labeled).

 This can be seen using the example below. Only sin(x) is included in the legend.

x = 0:0.1:10;
plotyy (x, sin (x), x, cos (x))
legend ("sin(x)" , "cos{x)")

In the Matlab implementation, both are labeled.


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 #21489:  changeset.patch added by bpabbott (8KiB - application/octet-stream - change to allow the gnuplot key outside the plotbox)
file #21386:  test_legend.m added by bpabbott (390B - application/octet-stream)
file #21387:  test_legend.pdf added by bpabbott (6KiB - application/pdf)

 

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 jwe (Updated the item)
  • -email is unavailable- added by dbateman (Posted a comment)
  • -email is unavailable- added by bpabbott
  • -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 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-11-07 dbateman StatusNone Fixed
        Open/ClosedOpen Closed
    2010-09-18 bpabbott Attached File- Added changeset.patch, #21489
    2010-09-16 jwe Priority5 - Normal 1 - Later
    2010-09-04 bpabbott Attached File- Added test_legend.m, #21386
        Attached File- Added test_legend.pdf, #21387
    2010-09-03 dbateman CategoryNone Interpreter
        Severity3 - Normal 1 - Wish
        Item GroupNone Feature Request
        Assigned toNone dbateman
    2010-09-03 bpabbott Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code