The plot in the figure shows some the stock on the market, but with this plot i no understand which stock
corresponds to each point.
the name of stocks are in: symbols = {'','',''.....}
if i use legend(symbols), matlab assigns the first name to the frontier, no to stock. i tryed legend("frontier", symbols) but it doesnt works.
is it possible to enter the names of stocks in the tips of the plot? with x and y...

 Respuesta aceptada

DGM
DGM el 21 de Ag. de 2021

1 voto

Store the handles, pass the handles to legend() and specify the names in a cell array.
h = plot(x,y);
for k = 1:K
% ...
h(k) = plot(thisx,thisy);
end
legend(h,{'this','that','other','etc'})

3 comentarios

Or set the DisplayName property of each line in the plot call then tell MATLAB to legend show. This puts the labeling information inside / near the plotting code, so there's less chance of them getting out of sync.
% Set up the data and graphics objects
x = 0:360;
k = 1:3;
h = gobjects(size(k));
axis([0 360 -1 1])
hold on
for whichK = k
% If I wanted to change sine to cosine I'd have to do it in two places
% in this command, not one place here and one place in the legend call
h(whichK) = plot(x, sind(whichK*x), '-', ...
'DisplayName', "sin(" + whichK + "*x)");
end
% No need to modify this line of code regardless of which function I plot
legend show
in this way i should write every single stock (the stocks are more than 100).
for this reason i wrote:
symbols = {'amazon','netflix'.....}
......
legend(symbols)
but the result is this:
Amazon is the first stocks, no the line. the line (is not in symbols) is a frontier.
i tryed like this:
legend('frontier', symbols)
but it doesnt works
I solved it this way. thanks to both.
symbols = {'','','',....}
ad = {'frontier'};
set = horzcat(ad,symbols);
legend(set, 'Location', 'best')

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Portfolio Optimization and Asset Allocation en Centro de ayuda y File Exchange.

Preguntada:

el 21 de Ag. de 2021

Comentada:

el 21 de Ag. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by