Wed 20 Dec 2017 05:26:42 PM UTC, comment #5:
I also agree that the script is confusing becasue there are 5 line objects for labeling spread across two axes. I re-wrote the script to be a little clearer and avoid greating the initial two line objects in the plotyy command.
This is attached as file tst_plotyy2.m.
Note that on 4.2.1 the new script no longer puts a thin line into the legend, but the legend objects are reversed such that the sine label is on the cosine color and vice versa. On the development branch this has been fixed and everything works correctly. For that reason I'm going to mark this report as fixed and close it.
Also, even in 4.2.1 you can get this to work by simply being explicit about what you want. If you know the particular objects you want to label, just tell the legend function what those are, rather than having it try to guess, and guess incorrectly.
In this case, the handle for the sine plot is already in H1 so change the cosine plot command to make sure you capture the handle
And then when you call legend give it the objects you want to label
(file #42691)
|
Wed 20 Dec 2017 05:04:04 PM UTC, comment #4:
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:
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:
and a second plot object is added to the second axis:
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:
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.
How about if I make the legend instead:
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 could instead do:
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.)
|
Tue 19 Dec 2017 09:53:26 PM UTC, original submission:
A legend added to a plot created with the plotyy command comes out wrong when it is located in the northeast. In this one location, the order of the plotstyle entries (not the string labels) is reversed.
Please see this example code together with the attached figures:
The legend is correct in all locations other than northeast, including all the outside versions.
I am using Windows 7 and have installed Octave using the w64 installer. I have found the issue to occur in the versions 4.2.0 and 4.2.1.
This bug may be related to https://savannah.gnu.org/bugs/?50497 or https://savannah.gnu.org/bugs/?35314, but neither of these covers the location dependence.
Final note: I do not need a patch, because applying it is beyond my expertise. I am only reporting it so that it can be fixed in a future version of Octave. In the meantime, my workaround is to plot the graphs in reverse order so that the legend comes out right.
|