juliaheatmapcolorbarformatter

how to set the format of the ticks of the colorbar when plotting the heatmap in Julia?


I'm new to Julia and have trouble plotting using Julia.

enter image description here

On the right side of the above plots,

The ticks of the colorbar in Hx_trs, and Hz_trs are not readable.

I want to print it in scientific notation, like 2e-6.

But I don't know how to do it...

the part of my code is written below:

trsfields = cat(real(Ex_trs), real(Hx_trs), real(Ey_trs), real(Hy_trs), real(Ez_trs), real(Hz_trs), dims=3)
ps = []
for (i, slice) in enumerate(eachslice(trsfields, dims=3))
    name = title[i]*"_trs"
    p = heatmap(slice, title=name, c=:coolwarm)
    push!(ps, p)
end
l = @layout([a d; b e; c f;])
plot(ps..., layout=l, plot_title="trs", size=(1200, 1000))
savefig("trs.png")

Here, trsfields is rank 3 tensor with size of (100, 150, 6). Each plot is a slice of the trsfields along the 3rd axis.

What keyword argument should I use when using the heatmap function?

I have searched for it in StackOverflow, Google, Official docs, and ChatGPT but couldn't find how.


Solution

  • You could do:

    using Plots
    pyplot()
    heatmap(rand(10,10);colorbar_ticks=(0.1:0.1:0.9, Printf.format.(Ref(Printf.format"%.3E"), 0.1:0.1:0.9)))
    

    enter image description here