How to Specify Heatmap Color Ranges in Julia
Code 1
When drawing a heatmap, sometimes it’s essential to fix the scale of values, so they don’t adjust with the numerical values. You can fix the color range using the clim
option in the basic heatmap function.
using Plots
cd(@__DIR__)
heatmap(rand(4,4)); png("1.png")
heatmap(rand(4,4), clim = (0,1)); png("2.png")
The results are as follows. The first heatmap has no fixed range, but the second heatmap’s range is fixed between 0 and 1, as you can see.
Limiting Only One Side
heatmap(rand(4,4), clim = (0,Inf))
heatmap(rand(4,4), clim = (-Inf,1))
If you want to set only an upper or a lower limit, you can do so by using Inf
as shown above to open the bounds.
Environment
- OS: Windows
- julia: v1.6.0