Two Stem Plots with Different Base Values on the Same Graph

조회 수: 25 (최근 30일)
Chien-Cheng Chiu
Chien-Cheng Chiu 2020년 9월 18일
답변: Dan 2020년 11월 5일
I want to plot two stem plots on the same graph so that "stem1" has a base value at 0 and "stem2" has a base value at -y_shift = 1. However, when I run the code, "stem1" would start on a base value at 0 for some time before its base value at 0 changes to the same base value as "stem2" and stays at the base value of -1. Is there any way to prevent that from happening?
for k = 1:10:m % for faster animations i.e. skip frame
z0 = u_approx_dirac(k,:);
z1 = dirac(k,:);
clf
hold on
plot(x, zeta(x), 'r');
plot(x_dirac , z0 , 'k');
stem1 = stem(x (z1 ~= 0), z1 (z1 ~= 0), 'filled', 'k');
set(stem1, 'LineWidth', 2, 'BaseValue', 0, 'ShowBaseLine', 'off');
time = t(1:2:k);
ref = reflectedwave(y(1:2:k));
dirac_ref = dirac_reflectedwave(y(2:2:k));
plot(time, ref - y_shift, 'b');
stem2 = stem(time (dirac_ref ~= 0), dirac_ref (dirac_ref ~= 0) - y_shift, 'filled', 'b');
set(stem2, 'BaseValue', -y_shift, 'ShowBaseLine', 'off');
legend(sprintf('t = %.6f', t(k)));
grid on
xlim([c d]);
xlabel('x');
ylim([-2 5]);
pause(0.00001);
hold off
frame = getframe(gcf);
writeVideo(v, frame);
end
close(v);

답변 (1개)

Dan
Dan 2020년 11월 5일
It seems that all the stem plots on the same axes are beholden to a common basevalue. This is step back from earlier versions of MATLAB ... to show two basevalues on the same axes, you can lay two axes on top of one another:
figure;
x = axes;
ylim([0,21])
xlim([0,11])
hold on
a=stem(1:10,'basevalue',10);
hold on
y = axes('position',x.Position);
ylim([0,21])
xlim([0,11])
set(y,'Color', 'none')
hold on
b=stem(11:20,'basevalue',20);
To get this plot:

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by