Hi, I’m struggling with plotting a simple matrix with log-scales for x, y and/or color-axis.
Consider e.g. a random 5*5 matrix
a, with associated values for
y axis (these values are always regularly spaced, either in linear or log space).
a = 10 .^(3*randn(5,5)) x = 10 .^(1:5) y = 1:5
So given these values, it makes sense to use logarithmic x- and color-scales.
I tried with Plots.jl, first with GR backend:
heatmap(10 .^(1:5), 1:5, a, xscale=:log10)
here the xticks are perfect, but not the rendering of the matrix…
xscale=:log10 option, the xticks are wrong… but the cells sizes well rendered:
Now, independently from this xticks behavior, let’s check the colors (these are probably two different problems, but I need to find a solution fixing the two together).
zscale=:log10 seems to be ineffective, so I tried to play with the color gradient to yield a good color rendering:
heatmap(10 .^(1:5), 1:5, a, cgrad=(scale=:log10))
I don’t quite understand how the transformation is computed, but it looks worse than before, so I also tried:
heatmap(10 .^(1:5), 1:5, a, cgrad=(scale=:exp))
which is better, but still not what I expect:
This should be compared to the range of colors you get when manually computing the log:
heatmap(10 .^(1:5), 1:5, log10.(a))
The colors are much better, but the colorbar is now useless.
Now I also tried with PyPlot backend and
The matrix display is great, but same problem with the colors.
Then I tried to use directly PyPlot, without Plots. I used the keyword argument
norm=matplotlib[:colors][:LogNorm] which solves the color problem, but I can’t get the ticks to render correcly.
imshow, I have trouble with the xaxis, even when using
PyPlot.imshow(a, cmap=:RdBu, norm=matplotlib[:colors][:LogNorm](),extent=[1, 10^5, 1, 5])
pcolor, I have a bug with the first column, and also the ticks are now aligned to the begin/end of the axis, but they should be aligned with the centers of the bins. With a lin-scale I could use that and play manually with xticks, but with a log-scale it us much more annoying.
PyPlot.pcolor(10 .^(1:6),1:6, a, cmap=:RdBu, norm=matplotlib[:colors][:LogNorm]())
So none of these options works properly to me, does anyone know how to get that working?
I’m using julia 1.1.0, Plots 0.25.3, PyPlot 2.8.1.