필터 지우기
필터 지우기

Change the width of the plot

조회 수: 4 (최근 30일)
Afsher P A
Afsher P A 2022년 1월 30일
편집: Afsher P A 2022년 2월 1일
How to change the line width of plot y3 ?
% Create some data to work with
x = 0:100:1000;
y1 = [0 137.9 288 442 598.1 755.5 913.7 1072 1231 1390 1600];
y2 = [NaN 61.93 30.95 20.62 15.46 12.368 10.309 8.83 7.73 6.868 6];
y3 = [0 3.229 6.461 9.697 12.93 16.17 19.4 22.65 25.87 29.12 33.33];
% Plot on the left and right y axes
figure
ax1 = axes;
yyaxis left % see [1]
plot(x,y1,'linewidth',1.5)
pause(0.1) % see [3]
% set the y(left) and x tick values, make them permanent
% This is the tricky part and shoudl receive a lot of thought when
% you adapt this to your code...
ax1.XTickMode = 'manual';
ax1.YTickMode = 'manual';
ax1.YLim = [min(ax1.YTick), max(ax1.YTick)]; % see [4]
ax1.XLimMode = 'manual';
grid(ax1,'on')
ytick = ax1.YTick;
yyaxis right % see [1]
plot(x,y2,'linewidth',1.5)
% create 2nd, transparent axes
ax2 = axes('position', ax1.Position);
plot(ax2,x,y3, 'k')
pause(0.1) % see [3]
ax2.Color = 'none';
grid(ax2, 'on')
% Horizontally scale the y axis to alight the grid (again, be careful!)
ax2.XLim = ax1.XLim;
ax2.XTick = ax1.XTick;
ax2.YLimMode = 'manual';
yl = ax2.YLim;
ax2.YTick = linspace(yl(1), yl(2), length(ytick)); % see [2]
% horzontally offset y tick labels
ax2.YTickLabel = strcat(ax2.YTickLabel, {' '});
% [1] https://www.mathworks.com/help/matlab/ref/yyaxis.html
% [2] this is the critical step to align the grids. It assumes both
% axes contain ticks at the start and end of the y axis
% [3] For some reason when I step through the code, the plots appear
% as they should but when I run the code at it's natural speed
% there are graphics issues. It's as if code execution is
% ahead of the graphics which is annoying. A brief pause
% fixes this (r2019a)
% [4] Scaling is easier if the ticks begin and end at the axis limits
  댓글 수: 2
Adam Danz
Adam Danz 2022년 1월 30일
편집: Adam Danz 2022년 1월 30일
Afsher P A
Afsher P A 2022년 2월 1일
Yes Sir. That's why I shared the question to you personally.

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

채택된 답변

KSSV
KSSV 2022년 1월 30일
Replace this line:
plot(ax2,x,y3, 'k')
with
plot(ax2,x,y3, 'k','LineWidth',5)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by