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)

采纳的回答

Matt J
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
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 CenterFile Exchange 中查找有关 Legend 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by