octave-bug-tracker
[Top][All Lists]

## [Octave-bug-tracker] [bug #52700] plotyy legend in reverse order

 From: Dan Sebald Subject: [Octave-bug-tracker] [bug #52700] plotyy legend in reverse order Date: Wed, 20 Dec 2017 12:04:04 -0500 (EST) User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

```Follow-up Comment #4, bug #52700 (project octave):

It's not uncommon for a bug to manifest differently for different systems.
The first step is confirming the bug and trying to characterize it.  I'm
testing on linux.  Typically, the more inconsistent bugs are related to a bad
pointer or index, i.e., some kind of randomness about it.

Is it certain that this works in Matlab?  The example generates an initial
plot with simple lines on it:

[AX,H1,H2]=plotyy([0 2*pi],[0 0], [0 2*pi],[0 0]);

So, I take it that means AX(1) has one plot object and AX(2) has one plot
object.  Note that the left axis AX(1) is highlighted with a thin cyan line
(and the right axis AX(2) a thin brown line).

At that point hold is turned on.

Next, a second and third plot object are added to the first axis:

plot(x,sine,'parent',AX(1),'b','linewidth',2);
plot(x,cosine,'parent',AX(1),'r','linewidth',2);

and a second plot object is added to the second axis:

plot(x,1.1*sine,'parent',AX(2),'g:','linewidth',1); % just to use the right
axis for something

So, at that point we have 3 plot objects on AX(1) and 2 plot objects on
AX(2).

Now, we specify just two legend entries for that first axis:

leg=legend(AX(1),'sine','cosine');

So, my suspicion is that there is something not quite programmed consistently
with regard to what to do in that situation.  On my system, somehow the legend
example line is being grabbed for the first legend entry.

leg=legend(AX(1),'extra line','sine','cosine');

I then see what looks like proper legend labeling and samples.  [BTW, that
dotted green line is extremely difficult to see on my system.  The ratio of
white space to green dot is rather large.]

The initial plot of lines from zero to two-pi seems somewhat extraneous.  One

x=0:.01:2*pi;
sine=sin(x);
cosine=cos(x);

figure
[AX,H1,H2]=plotyy(x,sine,x,1.1*sine);
set(H1,'color','b','linewidth',2);
set(H2,'color','g','linestyle',':','linewidth',1);
hold on
plot(x,cosine,'parent',AX(1),'r','linewidth',2);
xlim(AX(1), [0 2*pi]);
xlim(AX(2), [0 2*pi]);

leg=legend(AX(1),'sine','cosine');
set(leg,'location','northeast');

After those changes, I then see what I think you originally had in mind.

Anyway, what I see from your original code kind of makes sense in terms of the
legend.  The 'sine' text entry is actually labeling that initial flat line
from zero to two-pi.  The 'cosine' text entry is actually labeling the second
plot object which is the sine function.  So, the question is, Why is your
system producing one in which the first line is red, weight 2?

Oh, you are testing on Version 4.2.1?  This issue may have been fixed already.
As I said, I recall a group of us having debugged some of this plotyy legend
behavior in the not-too-distant past.  It's probably difficult for you to
build the development version for Windows. (I know nothing about the
Octave-for-Windows build process or who archives what where.)

_______________________________________________________

<http://savannah.gnu.org/bugs/?52700>

_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/

```