Two Stem Plots with Different Base Values on the Same Graph

26 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by