![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/404220/image.png)
Two Stem Plots with Different Base Values on the Same Graph
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
0 commentaires
Réponses (1)
Dan
le 5 Nov 2020
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/404220/image.png)
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!