Change the width of the plot
10 次查看(过去 30 天)
显示 更早的评论
How to change the line width of plot y3 ?
Code copied from https://www.mathworks.com/matlabcentral/answers/459385-multiple-y-axes-on-single-x-axis#answer_372987
% 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 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!