フィルターのクリア

stem plot with bars that don't go through zero

17 ビュー (過去 30 日間)
z8080
z8080 2016 年 7 月 5 日
回答済み: Thorsten 2016 年 7 月 5 日
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!

採用された回答

José-Luis
José-Luis 2016 年 7 月 5 日
lower_lim = -2 * rand(1,15);
upper_lim = 2 * rand(1,15);
x_val = (1:15);
aH = axes;
hold on;
for ii = [lower_lim;upper_lim;x_val]
plot(aH,[ii(3), ii(3)],[ii(1), ii(2)], 'b-');
end
mean_lim = (mean(lower_lim) + mean(upper_lim))/2;
plot(aH,aH.XLim,[mean_lim, mean_lim], 'r--');

その他の回答 (2 件)

Steven Lord
Steven Lord 2016 年 7 月 5 日
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
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

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by