在之前的文章中,分享了Matlab三维气泡图的绘制模板:

特征渲染的三维气泡图:

进一步,再来分享一下分组三维气泡图。
先来看一下成品效果:

特别提示:本期内容『数据+代码』已上传资源群中,加群的朋友请自行下载。有需要的朋友可以关注同名公号【阿昆的科研日常】,后台回复关键词【绘图桶】查看加入方式。
模板中最关键的部分内容:
1. 数据准备
此部分主要是读取原始数据并初始化绘图参数。
% 读取数据load data.mat% 初始化绘图参数X1 = x1;X2 = x2;Y1 = y;Y2 = y;Z1 = z;Z2 = z;SZ1 = sz1;SZ2 = sz2;
2. 颜色定义
作图不配色就好比做菜不放盐,总让人感觉少些味道。
但颜色搭配比较考验个人审美,需要多加尝试。
这里直接使用TheColor配色工具中的SCI权威配色库:
%% 颜色定义map = TheColor('sci',500);C1 = repmat(map(1,1:3),15,1);C2 = repmat(map(2,1:3),15,1);

3. 分组三维气泡图绘制
通过调用‘bubblechart3’命令,绘制初始分组三维气泡图。
t = tiledlayout(1,1);nexttilebubblechart3(X1,Y1,Z1,SZ1,C1)hold onbubblechart3(X2,Y2,Z2,SZ2,C2)bubblesize([5 30])view(-41,30)hTitle = title('Bubble3Grouped chart');hXLabel = xlabel('Xaxis');hYLabel = ylabel('Yaxis');hZLabel = zlabel('Zaxis');
4. 细节优化
为了插图的美观,对坐标轴细节等进行美化:
% 坐标区调整set(gca, 'Box', 'on', ... % 边框'XGrid', 'on', 'YGrid', 'on', 'ZGrid', 'on',... % 网格'TickDir', 'out', 'TickLength', [.01 .01], ... % 刻度'XColor', [.1 .1 .1], 'YColor', [.1 .1 .1],'ZColor', [.1 .1 .1]) % 坐标轴颜色% legendhLegend = legend('Sample1','Sample2','Linewidth',0.5);hLegend.Layout.Tile = 'east';% 气泡尺寸blgd = bubblelegend('SZ',...'Style','vertical',...'BubbleSizeOrder','descending',...'box','on',...'NumBubbles',3,... ...'FontName', 'Arial',...'FontSize', 9);blgd.Layout.Tile = 'east';bt = get(blgd,'Title');bt.FontWeight = 'normal';bt.FontName = 'Arial';bt.FontSize = 9;% 字体和字号set(gca, 'FontName', 'Arial', 'FontSize', 11)set([hLegend,hXLabel,hYLabel,hZLabel], 'FontName', 'Arial', 'FontSize', 11)set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')% 背景颜色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');

以上。



















