Plots with log or symlog scale

I’m trying to make plots with log and symlog scales, but no success with Plots.jl so far. When I try cgrad(scale=:log) it gives strange results, see below. And there seem to be no other place to specify log-scale.

A = randn(50, 100)
heatmap(log10.(abs.(A)), color=cgrad(:RdBu))
gives
image
which has correct colors, but of course wrong color scale: I need it to show original values instead of logs.
With scale=:log:
heatmap(abs.(A), color=cgrad(:RdBu, scale=:log))
image
I totally don’t get how it computes colors here. And also I don’t find anything related to symlog scale.

For comparison, using PyPlot:

imshow(log.(abs.(A)), cmap=:RdBu)
colorbar()

image
The same result as with Plots.
With log-scale:

imshow(abs.(A), cmap=:RdBu, norm=matplotlib[:colors][:LogNorm]())
colorbar()

image
This is the correct way to show log-scale plot.
And finally, symlog:

imshow(A, cmap=:RdBu, norm=matplotlib[:colors][:SymLogNorm](1e-2))
colorbar()

image

Is there a way to reproduce the last two plots (which use PyPlot) with Plots and non-pyplot backend?

1 Like

There’s a Gadfly example here:

But what about Plots.jl? I’m looking for an interactive web plot, using plotly backend.

1 Like

Here is how far I got with VegaLite.jl:

df |> @vlplot(
  :rect,
  x={"x:o", title=nothing},
  y={"y:o", title=nothing, sort=:ascending},
  color={"v:q", title=nothing, scale={typ=:log}},
  width=400, height=200,
  config={
    view={stroke=:transparent},
    range={heatmap={scheme="redblue"}}
  }
)

And that gives me:
examp

You would probably want to change how the axis are shown, and probably also adjust the color range for the scale.

Symlog scales are not supported at this point, but something that the vega/vega-lite team has on their radar: https://github.com/vega/vega/issues/1392.

You can create interactive web charts with vega-lite, the documentation for that is here. It is quite different from plotly, so not sure it would match your needs. But you should be able to export the vega-lite spec with yourspec |> save("foo.vegalite") and then follow the instructions for vega-lite embedding to put that onto a webpage.