气泡分组蝴蝶图是分组蝴蝶图与气泡图的组合——在分组蝴蝶图每组柱子上方添加大小不同的气泡,用于表示另外一个数据变量(如每组柱子值的和)的大小。
本文利用自己制作的BubbleButterfly工具,进行气泡分组蝴蝶图的绘制,先来看一下成品效果:

特别提示:本期内容『数据+代码』已上传资源群中,加群的朋友请自行下载。有需要的朋友可以关注同名公号【阿昆的科研日常】,后台回复关键词【绘图桶】查看加入方式。
1. 数据准备
此部分主要是读取原始数据并初始化绘图参数。
% 读取数据load data.mat% 初始化绘图参数butterflydata1 = x1;butterflydata2 = x2;bubbledata1 = y1;bubbledata2 = y2;offset1 = 800;textoffset1 = 100;offset2 = 800;textoffset2 = 100;bsz = [5 30];Label={'Sample1','Sample2','Sample3','Sample4','Sample5','Sample6','Sample7','Sample8'};
2. 颜色定义
作图不配色就好比做菜不放盐,总让人感觉少些味道。
但颜色搭配比较考验个人审美,需要多加尝试。
这里直接使用TheColor配色工具中的SCI权威配色库:
C = TheColor('sci',2057,'map',10);C1 = C(2,1:3);C2 = C(4,1:3);C3 = C(9,1:3);C4 = C(7,1:3);

3. 气泡分组蝴蝶图绘制
调用‘BubbleButterfly’和命令,绘制初始气泡分组蝴蝶图。
[ax1,ax2,b1,b2,bubble1,bubble2]=BubbleButterfly(figureHandle,butterflydata1,butterflydata2, ...bubbledata1,bubbledata2,offset1,offset2,bsz,Label,'normal');% 添加左翼气泡注释for i = 1:length(bubbledata1)text(ax1, ...offset1+textoffset1, i, num2str(bubbledata1(i)), ...'HorizontalAlignment','right', ...'VerticalAlignment','middle', ...'FontSize',10, ...'FontName','Arial', ...'color','k')end% 添加右翼气泡注释for i = 1:length(bubbledata2)text(ax2, ...offset2+textoffset2, i, num2str(bubbledata2(i)), ...'HorizontalAlignment','left', ...'VerticalAlignment','middle', ...'FontSize',10, ...'FontName','Arial', ...'color','k')end
4. 细节优化
为了插图的美观与信息完整性,对图形细节等进行美化:
% 左翼优化% 蝴蝶图属性调整b1(1).FaceColor = C1;b1(2).FaceColor = C2;% 气泡属性调整bubble1.MarkerFaceColor = C1;bubble1.MarkerEdgeColor = C1;bubble1.MarkerFaceAlpha = 1;% 坐标区调整set(ax1, 'Box','off',... % 边框'LineWidth',1,... % 坐标轴线宽'TickLength',[0 0],... % 刻度'XGrid','on','YGrid','off',... % 网格'XDir','reverse',... % X坐标轴方向'YDir','reverse',... % Y坐标轴方向'YAxisLocation','right',... % Y坐标轴位置'YTick',[]) % Y刻度ax1.XRuler.Axle.LineStyle = 'none';set(ax1, 'xtick',0:200:1000,...'xlim', [0 1000],...'ylim', [0.5 8.5])ax1.XRuler.Axle.LineStyle = 'none';% 标签及Legend1设置hLegend1 = legend(ax1, ...'Feature1','Feature2', ...'Location', 'northoutside',...'Orientation','horizontal');hLegend1.ItemTokenSize = [10 10];hLegend1.Box = 'off';% 字体字号set([ax1,hLegend1], 'FontName', 'Arial', 'FontSize', 9)% 右翼优化% 蝴蝶图属性调整b2(1).FaceColor = C3;b2(2).FaceColor = C4;% 气泡属性调整bubble2.MarkerFaceColor = C3;bubble2.MarkerEdgeColor = C3;bubble2.MarkerFaceAlpha = 1;% 坐标区调整set(ax2, 'Box','off',... % 边框'LineWidth',1,... % 坐标轴线宽'TickLength',[0 0],... % 刻度'XGrid','on','YGrid','off',... % 网格'XDir','normal',... % X坐标轴方向'YDir','reverse',... % Y坐标轴方向'YAxisLocation','left',... % Y坐标轴位置'YTick',[]) % Y刻度ax2.XRuler.Axle.LineStyle = 'none';set(ax2, 'xtick',0:200:1000,...'xlim', [0 1000],...'ylim', [0.5 8.5])ax2.XRuler.Axle.LineStyle = 'none';% 标签及Legend2设置hLegend2 = legend(ax2, ...'Feature3','Feature4', ...'Location', 'northoutside',...'Orientation','horizontal');hLegend2.ItemTokenSize = [10 10];hLegend2.Box = 'off';% 字体字号set([ax2,hLegend2], 'FontName', 'Arial', 'FontSize', 9)% 背景颜色set(gcf,'Color',[1 1 1])
设置完毕后,以期刊所需分辨率、格式输出图片。
%% 图片输出figW = figureWidth;figH = figureHeight;set(figureHandle,'PaperUnits',figureUnits);set(figureHandle,'PaperPosition',[0 0 figW figH]);fileout = 'test';print(figureHandle,[fileout,'.png'],'-r300','-dpng');

以上。


















