How to put legend in subplot automaticaly using for end?

3 ビュー (過去 30 日間)
nirwana
nirwana 2023 年 8 月 16 日
コメント済み: C B 2023 年 8 月 16 日
Can anyone help me how to put legend in left and right figure as shown below? Since this figure generate by looping (for-end), I wonder if legend can also generate using looping format

採用された回答

C B
C B 2023 年 8 月 16 日
For legend location as per image above you will need lcoation as
northeast
and
northwest
for more information you can refer here
  1 件のコメント
C B
C B 2023 年 8 月 16 日
or you can use text function to place annotation on subplots like below.
% Number of subplots
nPlots = 3;
% Number of lines per plot
nLines = 1;
figure;
for i = 1:nPlots
subplot(3, 3, i);
% Generate random data and plot
y = rand(1, 100);
plot(y);
hold on;
% Determine axes limits for positioning text
xlims = xlim;
ylims = ylim;
% Position text at top-right corner
xPosRight = xlims(2) - 0.05*(xlims(2) - xlims(1)); % 5% from the right edge
yPos = ylims(2) - 0.05*(ylims(2) - ylims(1)); % 5% from the top edge
text(xPosRight, yPos, num2str(randi([1, 99])), 'HorizontalAlignment', 'right');
% Position text at top-left corner
xPosLeft = xlims(1) + 0.05*(xlims(2) - xlims(1)); % 5% from the left edge
text(xPosLeft, yPos, num2str(randi([1, 99])), 'HorizontalAlignment', 'left');
hold off;
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by