common legend and common for multiple plots
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
Please how can include common axes and legend for multiple plots without doing it individually?
% Use LaTeX fonts
set(gca,'TickLabelInterpreter','latex');
tiledlayout(2,1, 'TileSpacing', 'compact')
nexttile
line1 = plot(sort(xivals), sort(intul),'b', 'DisplayName', '$\int u dy$');
hold on
line2 = plot(sort(xivals), sort(intabsul),'r', 'DisplayName', '$\int |u| dy$');
xlabel('activity, $\xi$ ','Interpreter','latex')
ylabel('$(\int u dy, \int |u| dy)$','Interpreter','latex')
title('Integral of $u$ at the left boundary','Interpreter','latex');
nexttile
line3 = plot(sort(xivals), sort(intur),'b', 'DisplayName','$\int u dy$');
hold on
line4 = plot(sort(xivals), sort(intabsur),'r', 'DisplayName', '$\int u dy$');
xlabel('activity, $\xi$ ','Interpreter','latex')
ylabel('$(\int u dy, \int |u| dy)$','Interpreter','latex')
title('Integral of $u$ at the right boundary','Interpreter','latex');
% Create a Legend with the data from multiple axes
lg = legend(nexttile(2), [line1,line2]);
lg.Location = 'southoutside';
lg.Orientation = 'horizontal';
% set all fonts size 10
set(findall(gcf,'-property','FontSize'),'FontSize',12)
0 件のコメント
採用された回答
Matt J
2023 年 11 月 2 日
編集済み: Matt J
2023 年 11 月 2 日
% Make up data:
xivals = 1:10;
intul = rand(1,10);
intabsul = rand(1,10);
intur = rand(1,10);
intabsur = rand(1,10);
% Use LaTeX fonts
set(gca,'TickLabelInterpreter','latex');
T=tiledlayout(2,1, 'TileSpacing', 'compact');
nexttile
line1 = plot(sort(xivals), sort(intul),'b', 'DisplayName', '$\int u dy$');
hold on
line2 = plot(sort(xivals), sort(intabsul),'r', 'DisplayName', '$\int |u| dy$');
title('Integral of $u$ at the left boundary','Interpreter','latex');
nexttile
line3 = plot(sort(xivals), sort(intur),'b', 'DisplayName','$\int u dy$');
hold on
line4 = plot(sort(xivals), sort(intabsur),'r', 'DisplayName', '$\int u dy$');
title('Integral of $u$ at the right boundary','Interpreter','latex');
% Create a Legend with the data from multiple axes
lg = legend(nexttile(2), [line1,line2],'Location','layout','Interpreter','latex');
lg.Orientation = 'vertical';
lg.Layout.Tile='east';
% set all fonts size 10
set(findall(gcf,'-property','FontSize'),'FontSize',12)
xlabel(T,'activity, $\xi$ ','Interpreter','latex')
ylabel(T,'$(\int u dy, \int |u| dy)$','Interpreter','latex')
4 件のコメント
Walter Roberson
2023 年 11 月 2 日
max(A,B) returns the element-by-element maximum of A with the corresponding element of B .
Now, suppose that B had locations that were 0 or negative, then the maximum of 1 and that value would be 1. But any location in B that was already at least 1, the maximum of that value and 1 would be that value.
So max(1,intsx(k2)-1) can be described as "intsx(k2)-1 if that is at least 1, but otherwise use 1"
Likewise min(numel(U),intsx(k2)+1) can be described as "intsx(k2)+1 if that does not exceed the number of elements in U, but use the number of elements in U if that value would exceed the number of elements"
So max(1,intsx(k2)-1) : min(numel(U),intsx(k2)+1) ends up creating the numeric vector of integers between intsx(k2)-1 and intsx(k2)+1 but clipping off any elements less than 1 or greater than the number of elements in U.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!