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...

 Réponse acceptée

DGM
DGM le 21 Août 2021

1 vote

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 commentaires

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')

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Portfolio Optimization and Asset Allocation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by