How to manage the legend?

Hi,

I would like to manage the content of the legend. In this example

plot(0:3,0:3,“g”,1,1,“b*”,2,2,“r^”)
legend(“a”,“b”,“c”,2);

there are three marks for the legends “b” and “c” (on Scilab 6.1.1.1626343451). Is it possible to have only one?

Thanks,
Jean-Yves

Hi Jean-Yves,

On your plot, you have 3 polylines with different renderings:

--> gca().children(2)
 ans  =

Handle of type "Compound" with properties:
==========================================
parent: Axes
children: ["Polyline";"Polyline";"Polyline"]
visible = "on"
user_data = []
tag = ""

The legend() function list them and displays each rendered line, one at a time. To only have a single listed item, either create a single line or use the compound containing the 3 lines as “legend link”.

Note: I never used the compound as legend link so it might not work.

Great! I have the solution

plot(0:3,0:3,"g",1,1,"b*",2,2,"r^")
legend("a","b","c",2);
gca().children(1).marks_count=1;

Tested on Scilab 6.1.1.
Many thanks.

Hello, at certain circumstances, I would like to disable the legend in the plot.

I tried following:

if condition then
    legend('off'); 
else
    legend(['Sinus', 'Kosinus']);  
end
--> legend();
at line     4 of function legend ( /home/smartie/Tools/scilab-2024.0.0/share/scilab/modules/graphics/macros/legend.sci line 17 )

legend: Wrong number of input argument(s): At least 1 expected.
--> h = gca(); 

-->  h.legends = []; 

Submatrix incorrectly defined.

Can you help me?

Thanks

Hello,

use the following command:

 delete(findobj(gca(),"type","Legend"));

S.

1 Like