Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

python - How to plot heatmap of 3 variables (depth, time, parameter)

I have temperature data which varies with time and depth (see attached example picture). My actual data set is lot bigger though. I was wondering how can I plot a heatmap. I am open to either Python or Matlab.

Thanks.

data

question from:https://stackoverflow.com/questions/65838286/how-to-plot-heatmap-of-3-variables-depth-time-parameter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In MATLAB

Below is an approach that uses the meshgrid() function to create a domain for the Temperature to be plotted on/against. To plot a 2D heat-map we can use surf() and set the elevation to a top view (90 degrees) by using the view() function. Depending if you wish to have interpolation or not the use of shading interp can be included or removed. To get the time labels we can convert the Time_Vector to a string array and use an arrayfunc() (array function) to replace the dot, . with a colon, :. Lastly we can use the set() function on the current axis, gca to display the newly formatted time labels on the plot. The colormap() can be set to a variety of options such as 'hot', 'winter', 'spring', etc.

Heatmap Variations

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);

Ran using MATLAB R2019b


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...