首页 > 解决方案 > 如何绘制 3 个变量(深度、时间、参数)的热图

问题描述

我有随时间和深度变化的温度数据(见附件示例图片)。不过,我的实际数据集要大得多。我想知道如何绘制热图。我对 Python 或 Matlab 持开放态度。

谢谢。

数据

标签: pythonmatlabplot2dheatmap

解决方案


在 MATLAB 中

下面是一种方法,它使用该meshgrid()函数创建一个域,以便在Temperature其上绘制/反对。要绘制 2D 热图,我们可以使用该函数surf()将高度设置为顶视图(90 度) 。view()根据您是否希望进行插值,shading interp可以包含或删除使用。要获取时间标签,我们可以将 转换Time_Vector为字符串数组并使用arrayfunc()(数组函数).用冒号替换点:。最后,我们可以使用set()当前轴上的函数,gca在绘图上显示新格式化的时间标签。colormap()可以设置为各种选项,例如、'hot''winter''spring'

热图变化

Time_Vector = (10.00: 0.01: 10.09);
Depth_Vector = (1:3);
Temperature = [15 16 17 18 19 20 20 20 20 20;
               25 30 35 40 45 50 50 50 50 50;
               30 35 40 45 50 55 60 65 70 75];

[Time_Grid,Depth_Grid] = meshgrid(Time_Vector,Depth_Vector);

surf(Time_Grid,Depth_Grid,Temperature);
title("Heatmap");
xlabel("Time"); ylabel("Depth");
colormap(hot);
shading interp
Angle = 0; Elevation = 90;
view(Angle,Elevation);
colorbar;

%Time label adjustments%
Time_Labels = string(Time_Vector);
Time_Labels = arrayfun(@(x) replace(x,".",":"),Time_Labels);
set(gca,'xtick',Time_Vector,'xticklabel',Time_Labels);

使用 MATLAB R2019b 运行


推荐阅读