Matlab热力图巅峰之作

准备'data.xlsx' 的热力图文件:

main:

Matlab 复制代码
clc;
clear;
close all;
% 相关性气泡热图

%% 数据准备
% 读取Excel文件数据
data = readmatrix('data.xlsx');  % 读取Excel文件中的数据

%% 颜色定义
map = colormap("cool"); 
map = map([2:6,9:13],1:3);

%% 图片尺寸设置(单位:厘米)
close all;
figureUnits = 'centimeters';
figureWidth = 15;
figureHeight = 12;

%% 窗口设置
figureHandle = figure;
set(gcf, 'Units', figureUnits, 'Position', [0 0 figureWidth figureHeight]);

%% 相关性气泡热图绘制
Cobubbleheatmap(data,50,600)
hTitle = title('Correlation bubble Heatmap Plot');
hXLabel = xlabel('K (w)');
hYLabel = ylabel('Samples');

%% 细节优化
% 赋色
colormap('cool')
cb = colorbar;
% 颜色条调整
caxis([-1 1])
set(cb,'TickDirection','out',...
       'TickLength',0,...
       'Ticks',-1:0.2:1)
% 坐标区调整
axis equal tight
set(gca, 'Box', 'off', ...                                % 边框
         'Layer','bottom',...                             % 图层
         'LineWidth',1,...                                % 线宽
         'XGrid', 'off', 'YGrid', 'off', ...              % 网格
         'TickDir', 'out', 'TickLength', [0 0], ...       % 刻度
         'XMinorTick', 'off', 'YMinorTick', 'off', ...    % 小刻度
         'XColor', [.1 .1 .1],  'YColor', [.1 .1 .1],...  % 坐标轴颜色
         'xtick',1:10,...                                 % 坐标轴刻度
         'xticklabels',1:10,...
         'ytick',1:10,...
         'yticklabels',1:10)
% 字体和字号
set(gca, 'FontName', 'Arial', 'FontSize', 10)
set([hXLabel, hYLabel], 'FontSize', 11, 'FontName', 'Arial')
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');

辅助函数:

Matlab 复制代码
function Cobubbleheatmap(data,minsz,maxsz)

% 构造气泡位置数据
x = 1:size(data,2);
y = 1:size(data,1);
[X,Y] = meshgrid(x,y);
Z = data;

% 构造网格数据
w = x(2)-x(1);
Xt = (x(1)-w/2):w:(x(end)+w/2);
Yt = (y(1)-y/2):w:(y(end)+y/2);
[Xmesh,Ymesh] = meshgrid(Xt,Yt);
Zmesh = zeros(size(Xmesh));

% 构造气泡尺寸数据
% 负
minznega = 0;
maxznega = 1;
negadataidx = find(data<0);
Snega = minsz+(abs(Z(negadataidx))-minznega)./(maxznega-minznega).*(maxsz-minsz);
% 正
minzposi = 0;
maxzposi = 1;
posidataidx = find(data>=0);
Sposi = minsz+(Z(posidataidx)-minzposi)./(maxzposi-minzposi).*(maxsz-minsz);


% 绘制相关性气泡热图
mesh(Xmesh,Ymesh,Zmesh,'EdgeColor','k','LineWidth',1)
hold on
scatter(X(negadataidx),Y(negadataidx),Snega,Z(negadataidx),'filled')
scatter(X(posidataidx),Y(posidataidx),Sposi,Z(posidataidx),'filled')
view(0,90)

end
相关推荐
侃侃_天下18 小时前
最终的信号类
开发语言·c++·算法
echoarts19 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix19 小时前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
每天回答3个问题19 小时前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说20 小时前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox
小莞尔20 小时前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
我是菜鸟0713号20 小时前
Qt 中 OPC UA 通讯实战
开发语言·qt
JCBP_20 小时前
QT(4)
开发语言·汇编·c++·qt·算法
Brookty21 小时前
【JavaEE】线程安全-内存可见性、指令全排序
java·开发语言·后端·java-ee·线程安全·内存可见性·指令重排序
百锦再21 小时前
[特殊字符] Python在CentOS系统执行深度指南
开发语言·python·plotly·django·centos·virtualenv·pygame