stem plot with bars that don't go through zero
显示 更早的评论
I'm trying to achieve a plot that looks like this . The stem plot seems to be the one to use, with a Y input having two columns for the lower and upper bounds, however it seems the vertical lines always have to be connected to the horizontal (zero) line of the plot. any way to make them independent of that line, for instance go from 3 to 5 on the y axis? Thanks!
采纳的回答
更多回答(2 个)
Steven Lord
2016-7-5
2 个投票
It sounds like either you want errorbars as created by the errorbar function or you want to change the baseline of your stem plot as per the last example on the stem documentation page.
Thorsten
2016-7-5
You can use my function stem2 to do it:
X = linspace(0,2*pi,50)';
Y = [cos(X), 0.5*sin(X)];
h = stem2(X,Y);
set(h, 'Color', 'b', 'LineWidth', 2)
with stem2 given as
function h = stem2(x, y)
%STEM2 Stem plot with upper and lower bounds
%
% H = STEM2(X, Y)
%
% Thorsten.Hansen@psychol.uni-giessen.de 2016-07-05
if nargin == 0 % demo
X = linspace(0,2*pi,50)';
Y = [cos(X), 0.5*sin(X)];
h = stem2(X,Y);
set(h, 'Color', 'b', 'LineWidth', 2)
clear h
return
end
if nargin == 1
y = x;
end
% check that y is a N*2 column vector
if size(y,2) ~= 2,
y = y';
if size(y, 2) == 2
warning('Y should be a Nx2 column vector.')
else
error('Y should be a Nx2 column vector.')
end
end
N = size(y, 1);
% generate x if not given
if nargin == 1
x = 1:N;
end
x = x(:); % force column vector
x = [x x nan(N,1)]';
y = [y nan(N,1)]';
h = plot(x(:), y(:));
if nargout == 0
clear h
end
类别
在 帮助中心 和 File 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!