필터 지우기
필터 지우기

When I drag the image, how can I make both the left and right Y-axis move?

조회 수: 10 (최근 30일)
x = 1:10;
y1 = sin(x);
y2 = cos(x);
yyaxis left;
plot(x, y1, 'b-');
yyaxis right;
plot(x, y2, 'r-');
linkaxes

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 12월 2일
편집: Dyuman Joshi 2023년 12월 2일
Here's an approach with adding another axis to the same tiled chart object and changing the y-axis location for the 2nd axes to right.
t = tiledlayout(1,1);
ax1 = axes(t);
x = 1:10;
y1 = sin(x);
y2 = cos(x);
plot(ax1, x, y1, 'b-');
ax2 = axes(t);
plot(ax2, x, y2, 'r-');
ax2.Color = 'none';
ax2.YAxisLocation = 'right';
%optional
%ax2.XAxis.Visible = 'off';
ax1.Box = 'off';
ax2.Box = 'off';
linkaxes([ax1 ax2])

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 12월 3일
One good solution is to download and use these functions created: https://www.mathworks.com/matlabcentral/fileexchange/102945-yyaxis-tools
x = 1:10;
y1 = sin(x);
y2 = cos(x);
figure;
yyaxis left;
plot(x, y1, 'b-');
yyaxis right;
plot(x, y2, 'r-');
yyaxtoolbar % Should be downloaded along with other three fcn files and put in your current MATLAB directory

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by