Legend behavior with several plots

Hi everyone,

I know there was a lot of improvements regarding plot legends but I am not sure whether the following change is intended: Until recently

plot (0:1:10, '-;some plot;');
plot (1:1:11, '-');

resulted in a legend with one entry ‘some plot’. Now, the same code leads to a legend showing two entries, namely ‘some plot’ and ‘data 1’. This makes it difficult to have a figure where further plots are added later, e.g., depending on user interaction.

Best regards
Torsten

Is there a typo in your first plot code line with the semicolons and a missing hold on? Matlab does not like the first line at all (error) and Octave just overwrites the plot (as expected).

The line is correct and works in Octave. But, you are right, I have omitted the complete “history” of my figure, including

hold on

Thanks for the clarification. I can confirm your observation for Octave 6 (69cba42a01ca 2020-07-29). In Octave 5.2.0 no dummy entry was created.

The legend behavior is now Matlab compatible, i.e., your command is equivalent to:

hold on;
plot (0:1:10, '-');
legend ("some plot");
plot (1:1:11, '-');

which produces the same output with “data 1” in Octave 6 and Matlab R2020a.

You get the desired result in Octave 5.2.0, Octave 6, and Matlab R2020a with:

hold on;
plot (0:1:10, '-');
plot (1:1:11, '-');
legend ("some plot");

Is there a reason to combine the plot command with passing the legend label?

You could also set the “autoupdate” property of the legend to “off”:

hold on;
plot (1:2, '-');
legend ("test", "autoupdate", "off");
plot (2:3, '-');
1 Like

Thanks for the replies! I wasn’t aware of the “autoupdate” option, which seems to be exactly what I need. Setting the legend at the end of all plots is not possible because I do not know if a plot is the last one or not.

The autoupdate option (together with a few other new options) is currently undocumented so there is no way to know it unless you read the NEWS file.
I have posted a preliminary patch here that adds documentation for a relevant selection of legend properties.