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!