How to output and save arrays as heatmap images in Julia
Heatmap
Using the heatmap
function from the Plots
package, you can output a 2D array as a heatmap image, and with the savefig
function, you can save the resulting image. The @__DIR__
macro tells you the location of the Julia code file.
# code1
However, if you compare array A with the heatmap image, you may notice that the top and bottom of the array are flipped in the heatmap image. The reason the output image is created this way is official crab talk says it’s because each element’s position is thought of not in terms of rows and columns but rather as coordinates in a Cartesian coordinate system. That is, for example, in the matrix $A$, the value 19 is not seen as an element in the 4th row and 4th column but as an element in Cartesian coordinates $(4,4)$. This explains why the matrix and the image are flipped upside down with respect to each other.
Therefore, to make the output look the same as the array, you can add the yflip=true
option1.
# code2
Moreover, users familiar with MATLAB can use the color=:bgy
option to get an output that closely matches MATLAB’s default colors.
# code3
Color Themes
The following are some of the available color themes.
See Also
Environment
- OS: Windows10
- Version: 1.5.3 (2020-11-09)