Matlab可绘制带误差线的柱状图(需下载barweb (BARgraph With Error Bars) - File Exchange - MATLAB Central并设置路径),成图如下所示。

代码:

close all;clear;clc;
X = [0.2267 0.1423 0.1427 0.1038; 0.1567 0.1184 0.1479 0; 0.1199 0.1035 0.1643 0; 0.1900 0.1540 0.1631 0]; %(系列数据)
E = [0.2808 0.1069 0.1092 0.1006; 0.1614 0.1003 0.1001 0; 0.1277 0.0789 0.1181 0; 0.2398 0.1518 0.1433 0];%(标准差)
legends = {'2019','2020','2021','2022'};%(图例)
groupnames = cell(4,1);
groupnames{1} = '1';groupnames{2} = '2';groupnames{3} = '3';groupnames{4} = '4';%(分组名称)
Title = '';
Xlabel = 'X';
Ylabel = 'Y';
barweb(X,E,1,groupnames,Title,Xlabel,Ylabel,jet,'none',legends,2,'plot');

设置配色及颜色对应可参考:

MATLAB绘制柱状图带标准误差线 - 爱码网

Matlab-RGB-颜色对照表(0-1之间取值)_循香而落的博客-CSDN博客_matlab颜色代码rgb

设置坐标轴和图例字体、大小可参考:

matlab——修改图中字体_DWQY的博客-CSDN博客_matlab图片字体

如果使用高版本Matlab,运行过程过程中可能会遇到以下(以及其他)问题

解决方式详见

在Matlab中使用barweb绘制带方差的分组柱状图时的几个注意事项_jbb0523的博客-CSDN博客

最后贴一下我自己修改后的代码(Maltab R2016a版本):

function handles = barweb(barvalues, errors, width, groupnames, bw_title, bw_xlabel, bw_ylabel, bw_colormap, gridstatus, bw_legend, error_sides, legend_type)%
% Usage: handles = barweb(barvalues, errors, width, groupnames, bw_title, bw_xlabel, bw_ylabel, bw_colormap, gridstatus, bw_legend, error_sides, legend_type)
%
% Ex: handles = barweb(my_barvalues, my_errors, [], [], [], [], [], bone, [], bw_legend, 1, 'axis')
%
% barweb is the m-by-n matrix of barvalues to be plotted.
% barweb calls the MATLAB bar function and plots m groups of n bars using the width and bw_colormap parameters.
% If you want all the bars to be the same color, then set bw_colormap equal to the RBG matrix value ie. (bw_colormap = [1 0 0] for all red bars)
% barweb then calls the MATLAB errorbar function to draw barvalues with error bars of length error.
% groupnames is an m-length cellstr vector of groupnames (i.e. groupnames = {'group 1'; 'group 2'}).  For no groupnames, enter [] or {}
% The errors matrix is of the same form of the barvalues matrix, namely m group of n errors.
% Gridstatus is either 'x','xy', 'y', or 'none' for no grid.
% No legend will be shown if the legend paramter is not provided
% 'error_sides = 2' plots +/- std while 'error_sides = 1' plots just + std
% legend_type = 'axis' produces the legend along the x-axis while legend_type = 'plot' produces the standard legend.  See figure for more details
%
% The following default values are used if parameters are left out or skipped by using [].
% width = 1 (0 < width < 1; widths greater than 1 will produce overlapping bars)
% groupnames = '1', '2', ... number_of_groups
% bw_title, bw_xlabel, bw_ylabel = []
% bw_color_map = jet
% gridstatus = 'none'
% bw_legend = []
% error_sides = 2;
% legend_type = 'plot';
%
% A list of handles are returned so that the user can change the properties of the plot
% handles.ax: handle to current axis
% handles.bars: handle to bar plot
% handles.errors: a vector of handles to the error plots, with each handle corresponding to a column in the error matrix
% handles.legend: handle to legend
%
%
% See the MATLAB functions bar and errorbar for more information
%
% Author: Bolu Ajiboye
% Created: October 18, 2005 (ver 1.0)
% Updated: Dec 07, 2006 (ver 2.1)
% Updated: July 21, 2008 (ver 2.3)% Get function arguments
if nargin < 2error('Must have at least the first two arguments:  barweb(barvalues, errors, width, groupnames, bw_title, bw_xlabel, bw_ylabel, bw_colormap, gridstatus, bw_legend, barwebtype)');
elseif nargin == 2width = 1;groupnames = 1:size(barvalues,1);bw_title = [];bw_xlabel = [];bw_ylabel = [];bw_colormap = jet;gridstatus = 'none';bw_legend = [];error_sides = 2;legend_type = 'plot';
elseif nargin == 3groupnames = 1:size(barvalues,1);bw_title = [];bw_xlabel = [];bw_ylabel = [];bw_colormap = jet;gridstatus = 'none';bw_legend = [];error_sides = 2;legend_type = 'plot';
elseif nargin == 4bw_title = [];bw_xlabel = [];bw_ylabel = [];bw_colormap = jet;gridstatus = 'none';bw_legend = [];error_sides = 2;legend_type = 'plot';
elseif nargin == 5bw_xlabel = [];bw_ylabel = [];bw_colormap = jet;gridstatus = 'none';bw_legend = [];error_sides = 2;legend_type = 'plot';
elseif nargin == 6bw_ylabel = [];bw_colormap = jet;gridstatus = 'none';bw_legend = [];error_sides = 2;legend_type = 'plot';
elseif nargin == 7bw_colormap = jet;gridstatus = 'none';bw_legend = [];error_sides = 2;legend_type = 'plot';
elseif nargin == 8gridstatus = 'none';bw_legend = [];error_sides = 2;legend_type = 'plot';
elseif nargin == 9bw_legend = [];error_sides = 2;legend_type = 'plot';
elseif nargin == 10error_sides = 2;legend_type = 'plot';
elseif nargin == 11legend_type = 'plot';
endchange_axis = 0;
ymax = 0;if size(barvalues,1) ~= size(errors,1) || size(barvalues,2) ~= size(errors,2)error('barvalues and errors matrix must be of same dimension');
elseif size(barvalues,2) == 1barvalues = barvalues';errors = errors';endif size(barvalues,1) == 1barvalues = [barvalues; zeros(1,length(barvalues))];errors = [errors; zeros(1,size(barvalues,2))];change_axis = 1;endnumgroups = size(barvalues, 1); % number of groupsnumbars = size(barvalues, 2); % number of bars in a groupif isempty(width)width = 1;end% Plot barshandles.bars = bar(barvalues, width,'edgecolor','k', 'linewidth', 2);hold onif ~isempty(bw_colormap)barmap=[0.39 0.58 0.92; 0.60 0.80 0.196; 0.93 0.87 0.51; 1 0.64 0];colormap(barmap);elsecolormap(barmap);endif ~isempty(bw_legend) && ~strcmp(legend_type, 'axis')handles.legend = legend(bw_legend, 'fontsize', 24);elsehandles.legend = [];end% Plot errosfor i = 1:numbarsx = handles.bars(i).XData + handles.bars(i).XOffset;handles.errors(i) = errorbar(x, barvalues(:,i), errors(:,i), 'k', 'linestyle', 'none', 'linewidth', 2);ymax = max([ymax; barvalues(:,i)+errors(:,i)]);endif error_sides == 1set(gca,'children', flipud(get(gca,'children')));endylim([0 ymax*1.1]);xlim([0.5 numgroups-change_axis+0.5]);if strcmp(legend_type, 'axis')for i = 1:numbarsxdata = get(handles.errors(i),'xdata');for j = 1:length(xdata)text(xdata(j),  -0.03*ymax*1.1, bw_legend(i), 'Rotation', 60, 'fontsize', 24, 'HorizontalAlignment', 'right');endendset(gca,'xaxislocation','top');endif ~isempty(bw_title)title(bw_title, 'fontsize',24,'FontWeight','bold','FontName','Times New Roman');endif ~isempty(bw_xlabel)xlabel(bw_xlabel, 'fontsize',24,'FontWeight','bold','FontName','Times New Roman');endif ~isempty(bw_ylabel)ylabel(bw_ylabel, 'fontsize',24,'FontWeight','bold','FontName','Times New Roman');endset(gca, 'xticklabel', groupnames, 'box', 'on', 'ticklength', [.01 .01], 'fontsize', 24,'FontWeight','bold','FontName','Times New Roman', 'xtick',1:numgroups, 'linewidth', 2,'xgrid','off','ygrid','off');if ~isempty(gridstatus) && any(gridstatus == 'x')set(gca,'xgrid','on');endif ~isempty(gridstatus) && any(gridstatus ==  'y')set(gca,'ygrid','on');endhandles.ax = gca;hold off
end

Matlab绘制带误差线的柱状图相关推荐

  1. R - ggplot绘制带误差线的柱状图

    ggplot绘制带误差线的柱状图 利用ggplot2 数据格式转换并做统计计算 绘制图形 ## 模拟 ## 导入包 library(ggplot2) library(reshape2) library ...

  2. Python+Matplotlib绘制带误差线的柱状图

    推荐图书: <Python程序设计(第3版)>,(ISBN:978-7-302-55083-9),董付国,清华大学出版社,2020年6月第1次印刷,2021年12月第11次印刷,山东省一流 ...

  3. matlab 条形图误差线,数据可视化系列:手把手教你绘制带误差线的条形图

    原标题:数据可视化系列:手把手教你绘制带误差线的条形图 条形图可以用于展示数据不同分类下的均值.中位数.标准差和置信区间等,Excel可以实现,但对于带误差线的条形图而言,还是比较麻烦的.R语言的基础 ...

  4. python-科研绘图系列(1)-带误差线的柱状图

    1.带误差线的柱状图 import numpy as np import pandas as pd import matplotlib.pyplot as pltfig=plt.figure(figs ...

  5. 绘制带有误差线的柱状图

    绘制带有误差线的柱状图,代码比较简单就不再解释了 # a stacked bar plot with errorbars import numpy as np import matplotlib.py ...

  6. R语言绘制带误差线的条形图

    条形统计图是用一个单位长度表示一定的数量,根据数量的多少画成长短不同的直条.带误差的条形图可以通过误差线来判断显著性. 继续使用我们的汽车销售数据(公众号回复:汽车销售,可以获得该数据)来演示,先导入 ...

  7. Python绘制带误差线的图形 Python plots with error bands

    If you want to plot a function curve with multiple parameters with errors, one way to visualize the ...

  8. python绘制带误差线的条形图

    绘制格式: plt.bar(index, values, yerr = std, error_kw = {'ecolor' : '0.2', 'capsize' :6}, alpha=0.7) yer ...

  9. 3.3带误差线的柱状图

最新文章

  1. 【实战篇】| 小鹿教你用动态规划撩妹的正确方式
  2. mysql boost 5.7.21_mysql 5.7.21 安装配置方法图文教程(window)
  3. 组合数学 —— 概述
  4. matlab中x从0到5不含0,关于MATLAB的数学建模算法学习笔记
  5. sprintf函数实现_从Go结构成员的升格到面向对象类的实现
  6. Windows环境下使用CMake编译OpenCV3.0和OpenCV_contrib
  7. java代码表示非空链表整数_Leetcode: Topic 2 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的.......
  8. hg diff仅对当前目录下的文件有效
  9. 计算机信息管理系统实训摘要,计算机实训报告摘要.doc
  10. DSP初识-20151111
  11. java做一个客房管理系统定制_基于jsp的客房管理系统-JavaEE实现客房管理系统 - java项目源码...
  12. 浅谈Android自定义View
  13. VScode 光标乱跳
  14. 天津大学计算机学院课表,天津大学软件实践1汇编语言课程教学大纲-天津大学计算机学院.PDF...
  15. 京东商城空调标价0元引发抢购
  16. s5p6818PWM驱动蜂鸣器实验
  17. 挂一漏万——交通相关微信公共账号(V1)
  18. 手机电脑维修管理系统
  19. 这不是TNT:py挂机脚本
  20. GPS L5软件接收机的编写

热门文章

  1. JavaScript | 正则表达式
  2. Unity吃豆人敌人BFS广度(宽度)优先算法实现怪物追踪玩家寻路
  3. kaldi查看不同文件的命令集锦
  4. 高通增强现实SDK开发实例,COCOACHINA首发。qualcomm ar sdk
  5. JVM的基本结构及其各部分详解(一)
  6. SitePoint Podcast#173:释放混乱的猴子
  7. 全文翻译【YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors】
  8. linux gsoap交叉编译,Gsoap交叉编译
  9. IBM服务器找不到硬盘怎么设置,关于IBM x3400服务器找不到硬盘(RAID0)問題
  10. rust新版组队指令_新版rust指令是啥啊?