这个图片很有意思:娱乐局
于是使用matlab重复以下:
本想使用matlab 的bar,但发现使用上次的基线平移会失败,因为会把所有的柱状图都放在同一个基线上面:
就是用自己的patch.和for循环结合下:
for i = 1:11
xx = [i-0.4 i+0.4 i+0.4 i-0.4];
y = [num-(i-1)*num/num2+x1(i) num-(i-1)*num/num2+x1(i) num-(i-1)*num/num2+x2(i)+x1(i) num-(i-1)*num/num2+x2(i)+x1(i)];
patch(xx,y,[3 166,44]./255,'edgecolor','none')
hold on
end
全部代码如下:
clear;clc;close all;
%%数据构造:
x1 = 11:-1:1;
x2 = 22:-1:12;
x3= 33:-1:23;
x = cat(1,x1,x2,x3);
figure
set(gcf,'position',[50 50 850 500],'color','w')
h=bar(1:11,ones(11,1)*100,0.8);
set(h(1),'FaceColor',[135 206 250]./255);
hold on
y = 1:11;
h=bar(y,x,'stacked');
set(h(1),'FaceColor',[242,159,5]./255);
set(h(2),'FaceColor',[3 166,44]./255);
set(h(3),'FaceColor',[242 5 5]./255);
for i = 1:10
hold on
line([0.6 12-0.6],[i*10 i*10],'color','k')
end
xlim([0.6 12-0.6])
set(gca,'xtick',[1:11],'xticklabel',[1:11],'ytick',[0:10:100],'yticklabel',[0:10:100],'linewidth',1)
ytickformat('%,.0f \%')
export_fig('bar_1.jpg','-r600')
%%
clear;clc;close all;
%%数据构造:
x1 = 11:-1:1;
x2 = 22:-1:12;
x3= 33:-1:23;
x = cat(1,x1,x2,x3);
num = 20;% 平移距离
num2 = 15;% 控制下移距离
gray = [0.6 0.6 0.6];
figure
set(gcf,'position',[50 50 850 500],'color','w')
h=bar(1:11,ones(11,1)*100,0.8);
set(h(1),'FaceColor',[135 206 250]./255);
hold on
%01
for i = 1:11
xx = [i-0.4 i+0.4 i+0.4 i-0.4];
y = [num-(i-1)*num/num2 num-(i-1)*num/num2 num-(i-1)*num/num2+x1(i) num-(i-1)*num/num2+x1(i)];
patch(xx,y,[242,159,5]./255,'edgecolor','none')
hold on
end
% 02
for i = 1:11
xx = [i-0.4 i+0.4 i+0.4 i-0.4];
y = [num-(i-1)*num/num2+x1(i) num-(i-1)*num/num2+x1(i) num-(i-1)*num/num2+x2(i)+x1(i) num-(i-1)*num/num2+x2(i)+x1(i)];
patch(xx,y,[3 166,44]./255,'edgecolor','none')
hold on
end
% 03
for i = 1:11
xx = [i-0.4 i+0.4 i+0.4 i-0.4];
y = [num-(i-1)*num/num2+x1(i)+x2(i) num-(i-1)*num/num2+x1(i)+x2(i) num-(i-1)*num/num2+x2(i)+x1(i)+x2(i) num-(i-1)*num/num2+x2(i)+x1(i)+x2(i)];
patch(xx,y,[242 5 5]./255,'edgecolor','none')
hold on
end
ylim([0 100])
xlim([0.6 12-0.6])
% 竖线
box on
for i = 1:11
hold on
line([i-0.4 i-0.4],[0 100],'color',gray)
hold on
line([i+0.4 i+0.4],[0 100],'color',gray)
end
% % 横线
for i = 1:10
hold on
line([0.6 12-0.6],[i*10 i*10],'color',gray)
end
set(gca,'xtick',[1:11],'xticklabel',[1:11],'ytick',[0:10:100],'yticklabel',[0:10:100],'linewidth',1)
ytickformat('%,.0f \%')
export_fig('bar_2.jpg','-r600')