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

 採用された回答

DGM
DGM 2021 年 8 月 21 日

1 投票

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 件のコメント

Steven Lord
Steven Lord 2021 年 8 月 21 日
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
Daniele Clementini
Daniele Clementini 2021 年 8 月 21 日
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
Daniele Clementini
Daniele Clementini 2021 年 8 月 21 日
I solved it this way. thanks to both.
symbols = {'','','',....}
ad = {'frontier'};
set = horzcat(ad,symbols);
legend(set, 'Location', 'best')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePortfolio Optimization and Asset Allocation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by