필터 지우기
필터 지우기

common legend and common for multiple plots

조회 수: 2 (최근 30일)
University
University 2023년 11월 2일
댓글: University 2023년 11월 2일
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.
University
University 2023년 11월 2일
Thank you so much Walter.

댓글을 달려면 로그인하십시오.

추가 답변 (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