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!