x = linspace(-2*pi,2*pi,100);
y = 4*pi*randn(1,100)-2*pi;
figure;
stem(x,y, 'LineWidth', 3)
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Stem Test', 'NumberTitle', 'Off')
hi, i want to plot it in vertical mode

 Réponse acceptée

Voss
Voss le 18 Mar 2025
x = linspace(-2*pi,2*pi,100);
y = 4*pi*randn(1,100)-2*pi;
% Set up figure properties:
% Enlarge figure to full screen.
% Get rid of tool bar and pulldown menus that are along top of figure.
% Give a name to the title bar.
figure('Units', 'Normalized', 'OuterPosition', [0 0 1 1], 'Toolbar', 'none', ...
'Menu', 'none', 'Name', 'Stem Test', 'NumberTitle', 'Off');
ax = gca();
hold(ax,'on');
box(ax,'on');
ax.YDir = 'reverse';
ax.ColorOrder = ax.ColorOrder(1,:);
plot(ax,y,x,'o','LineWidth',3)
N = numel(x);
xx = [x;x;NaN(1,N)];
yy = [y;zeros(1,N);NaN(1,N)];
plot(ax,yy(:),xx(:),'LineWidth',3)
xline(ax,0)

4 commentaires

shamal
shamal le 20 Mar 2025
excuse me but it possibile green color the number positive and red color the number negative?
i try to do it but i can't
Voss
Voss le 20 Mar 2025
Modifié(e) : Voss le 20 Mar 2025
Here's one way (points with y == 0 are blue):
x = linspace(-2*pi,2*pi,100);
y = 4*pi*randn(1,100)-2*pi;
figure('Units', 'Normalized', 'OuterPosition', [0 0 1 1], 'Toolbar', 'none', ...
'Menu', 'none', 'Name', 'Stem Test', 'NumberTitle', 'Off');
ax = gca();
hold(ax,'on');
box(ax,'on');
ax.YDir = 'reverse';
pos = y > 0;
neg = y < 0;
zer = ~pos & ~neg;
plot(ax,y(pos),x(pos),'go','LineWidth',3)
plot(ax,y(neg),x(neg),'ro','LineWidth',3)
plot(ax,y(zer),x(zer),'bo','LineWidth',3)
N = nnz(pos);
xx = [x(pos);x(pos);NaN(1,N)];
yy = [y(pos);zeros(1,N);NaN(1,N)];
plot(ax,yy(:),xx(:),'g','LineWidth',3)
N = nnz(neg);
xx = [x(neg);x(neg);NaN(1,N)];
yy = [y(neg);zeros(1,N);NaN(1,N)];
plot(ax,yy(:),xx(:),'r','LineWidth',3)
N = nnz(zer);
xx = [x(zer);x(zer);NaN(1,N)];
yy = [y(zer);zeros(1,N);NaN(1,N)];
plot(ax,yy(:),xx(:),'b','LineWidth',3)
xline(ax,0)
shamal
shamal le 20 Mar 2025
thanks you...very good
Voss
Voss le 21 Mar 2025
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 18 Mar 2025

0 votes

One method is to create a hgtransform and use that as the parent axes of the stem() call. Then set the Matrix property of the hgtransform to rotate the stem plot; it is often useful to use makehgtform to create the rotation matrix.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by