버전 (429 KB) 작성자: Rob Campbell
Creates an attractive shaded error region rather than discrete bars.
다운로드 수: 43.3K
업데이트 날짜: 2024/2/6

편집자 메모: This file was selected as MATLAB Central Pick of the Week


View raacampbell/shadedErrorBar on File Exchange Open in MATLAB Online

shadedErrorBar is a MATLAB function that creates a continuous shaded error region around a line rather than discrete bars. The error region can either be specified explicitly or calculated on the fly based on function handles. The appearance of the plot can be modified via input arguments and/or the handles of the returned plot objects. You will need OpenGL enabled for transparency to work.


Basic example with overlaid points

% Prepare data
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP)+60;

% Make the plot

% Overlay the raw data
hold on

grid on

Overlaying multiple lines

% Prepare data for first line


% Overlay second line
hold on

%Overlay third line
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP)+60;

% Make this line non-transparent
shadedErrorBar(x, y, {@mean,@std}, 'lineprops', '-r','transparent',false,'patchSaturation',0.075)

grid on

Modifying plot properties post-hoc

% Prepare data
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP);

% Plot
s = shadedErrorBar(x, y, {@mean,@std}, 'lineprops', '-r');

% Set face and edge properties
s.mainLine.LineWidth = 5;
s.patch.FaceColor = [0.5,0.25,0.25];

% Overlay data points post-hoc
hold on
plot(s.mainLine.XData, s.mainLine.YData,'or','MarkerFaceColor','w')

grid on


Change Log

15tth November 2022

  • Allow targing to a specific axis

8th Novemeber 2019

  • Merge Octave support from JarlPed

24th November 2017

  • Add patchSaturation as an optional argument.

6th August 2017

  • Parameter/value pairs for input arguments greater than 3.
  • Transparency on by default.
  • No longer changes the renderer.


If you wish to contribute please fork the repo, check out the dev branch and make your changes there, then file a pull request describing what you did.


This code is licensed under the lesser GPL v3. See LICENSE file in the repository.

인용 양식

Rob Campbell (2024). raacampbell/shadedErrorBar (https://github.com/raacampbell/shadedErrorBar), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2015b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
Help CenterMATLAB Answers에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

GitHub 디폴트 브랜치를 사용하는 버전은 다운로드할 수 없음

버전 게시됨 릴리스 정보

Rename demo files to avoid name clashes. Trivial changes in demo.

typos on readme

Update readme with MATLAB online button and add livescript example.

doc update

Provide "patchSaturation" optional input argument. Update demos.

github for questions
update description

move to GitHub

Verified to work with R2015a

Handles now only returned if the user requests them. Plot elements are re-ordered in a more elegant manner.

Improved error-checking of input args and revised some of the comments.

Correct bug that caused patch area not to be plotted when y contained NaNs and error bars were generated using the function handles approach.

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.