How to create a smooth heatmap for 1D ?

31 views (last 30 days)
I have the temperature values for the variable Y for 8 node points in 1D . Now when I try to plot I get the temperature gradient as individual boxes as shown below. I dont want this. The code for achieving this result is shown below
heatmap_1d.jpg
Y =
1.0e+03 *
4.1962
3.5087
2.8783
2.3026
1.7775
1.2967
0.8516
0.4318
figure(1)
imagesc(Y)
axis equal
axis off
colorbar;
Annotation 2019-07-13 011733.png
I need to get an smooth image like the one shown in second figure where the transition is smooth between the temperature gradients.
Any help will be appreciated !
  1 Comment
infinity
infinity on 13 Jul 2019
Hello,
The problem is that your data is very coarse. You got the temperature only at 8 points. One of the tasks you shoud be done first is to inpterpolate your data to the finer mesh.
When you obtain smoother data, you can plot smoother figure.

Sign in to comment.

Accepted Answer

Sai Bhargav Avula
Sai Bhargav Avula on 16 Jul 2019
Edited: Sai Bhargav Avula on 16 Jul 2019
Hi Sreenivas,
You are trying to generate the heatmap using only 8 points. Try to interpolate the data using the interp1 function.
For our case:
Y = 1000*[4.1962 3.5087 2.8783 2.3026 1.7775 1.2967 0.8516 0.4318];
X = linspace(1,10,100);
Y = interp1(Y,X);
imagesc(Y);
axis equal
axis off;
colorbar;
Here X is an equally spaced array of 100 elements and is the second argument for the interp1 function. The interp1 function considers the Y as a function and queries for the Y values at each value of X. This results in a Y array with 100 elements, which is ufficient to generate a smooth 1D heat map.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!