1.条形图种类
1.1二维条形图
Y = [5,2,1
8,7,3
9,8,6
5,5,5
4,3,2];
figure
bar(Y)
figure
bar(Y,'stacked')
1.2二维水平条形图
Y = [5,2,1
8,7,3
9,8,6
5,5,5
4,3,2];
figure
barh(Y)
1.3三维条形图
Y = [5,2,1
8,7,3
9,8,6
5,5,5
4,3,2];
figure
bar3(Y)
figure
bar3(Y,'stacked')
1.4三维水平条形图
Y = [5,2,1
8,7,3
9,8,6
5,5,5
4,3,2];
figure
bar3h(Y)
2.修改条形图的基准线
Y = [5, 4, 3, 5;
3, 6, 3, 1;
4, 3, 5, 4];
b = bar(Y);
b(1).BaseValue = 2;
b(1).BaseLine.LineStyle = ':';
b(1).BaseLine.Color = 'red';
b(1).BaseLine.LineWidth = 2;
3.叠加条形图
x = [1 2 3 4 5];
temp_high = [37 39 46 56 67];
w1 = 0.5;
bar(x,temp_high,w1,'FaceColor',[0.2 0.2 0.5])
temp_low = [22 24 32 41 50];
w2 = .25;
hold on
bar(x,temp_low,w2,'FaceColor',[0 0.7 0.7])
hold off
grid on
ylabel('Temperature (\circF)')
legend({'Average High','Average Low'},'Location','northwest')
ax = gca;
ax.XTick = [1 2 3 4 5];
ax.XTickLabels = {'January','February','March','April','May'};
ax.XTickLabelRotation = 45;
4.带有误差条的条形图
x = 1:13;
data = [37.6 24.5 14.6 18.1 19.5 8.1 28.5 7.9 3.3 4.1 7.9 1.9 4.3]';
errhigh = [2.1 4.4 0.4 3.3 2.5 0.4 1.6 0.8 0.6 0.8 2.2 0.9 1.5];
errlow = [4.4 2.4 2.3 0.5 1.6 1.5 4.5 1.5 0.4 1.2 1.3 0.8 1.9];
bar(x,data)
hold on
er = errorbar(x,data,errlow,errhigh);
er.Color = [0 0 0];
er.LineStyle = 'none';
hold off
Z = magic(5);
b = bar3(Z);
colorbar
文章来源:https://www.toymoban.com/news/detail-856898.html
for k = 1:length(b)
zdata = b(k).ZData;
b(k).CData = zdata;
b(k).FaceColor = 'interp';
end
文章来源地址https://www.toymoban.com/news/detail-856898.html
到了这里,关于matlab使用教程(46)—绘制条形图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!