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

 Accepted Answer

DGM
DGM on 21 Aug 2021
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 Comments

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

Sign in to comment.

More Answers (0)

Categories

Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!