line vs plot: Multiple axes

조회 수: 1 (최근 30일)
Pankaj
Pankaj 2018년 11월 10일
댓글: dpb 2018년 11월 10일
I tried the example code for Creating Chart with Multiple x-Axes and y-Axes from this link. The code is as follows:
figure
x1 = 0:0.1:40;
y1 = 4.*cos(x1)./(x1+2);
line(x1,y1,'Color','r')
ax1 = gca; % current axes
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
x2 = 1:0.2:20;
y2 = x2.^2./x2.^3;
line(x2,y2,'Parent',ax2,'Color','k')
But if I replace line function with plot, it does not give me desired output. Does line and plot work differently?
  댓글 수: 1
dpb
dpb 2018년 11월 10일
You have already answered the question posed...the results weren't the same were they? :)
plot is a "high level" and line is a "low(er) level" function; with plot many behind the scenes details are done when the function is called while line simply puts the points on the existing axis.
At minimum,
hold(ax1,'on')
first or use the named property 'NextPlot' with plot as 'NextPlot','Add'

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

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