How to save a heatmap as a png?

#1

I can plot a matrix as a heatmap and I can even choose my own colormap. But how can I save just the heatmap (not the plot) as a png-file? For example:

using Plots
gr()

xs = range(-1, 1, length=30)
ys = range(-1, 1, length=30)
zs = randn(30, 30)
whiteblue = cgrad([:white, :blue])
heatmap(xs, ys, zs, colorbar=false, color=whiteblue)

Is there any way to save the matrix as a png, possibly with a custom colormap? I can do

using Images
using FileIO
save(File(format"PNG", "map.png"), colorview(Gray, zs))

Is this even close that what I want? Can I change the colormap? I would prefer to have the same colormap as in the heatmap plot, but that is not strictly necessary, something similar is also fine. Maybe I just failed to spot it in the docs.

#2
help?> savefig
search: savefig StackOverflowError

  savefig([plot,] filename)

  Save a Plot (the current plot if plot is not passed) to file. The file type is inferred from the file extension. All backends support png and pdf file types, some
  also support svg, ps, eps, html and tex.
#3

Sorry for being unclear. I don’t want to save the Plot. I want to just save the heatmap (like, the picture that is inside the axis). No axis, no padding, just the heatmap.

#4

Look into Images.jl

Create image from your matrix. Of course you need to make your own colorscale

#5

Ok, thanks! I thought that the colorview was exactly for that, but I should look for something else then? What is a colorscale (apparently something else than cgrad)? Where do I find documentation for that?

#6

You could also do the plot without any axes etc. and either adjust the axis-size to the figure size, or use some command-line tool to crop the white border.