Plots.jl
Plots.jl copied to clipboard
GR: heatmap and line plot with linked axes not aligned correctly
plot( heatmap(1:10,1:10, (x,y)->x/(x+y)),
plot(1:10,rand(10)),
layout=(2,1), link=:x )
On GR:
The line plot did cause the heatmap x axis to widen, but the x axes are not aligned.
In PyPlot, the same example looks fine.
In PlotlyJS the alignment is ok, and it helpfully hides the axes on the top plot (could be a nice feature in other backends too). But there's a mysterious line near the top of the colorbar (I guess it's part of the legend, so it's probably related to #694)
Yes I think this is due to GR's behaviour with colour bars, where it plots the color bar as part of the plot. So the axes are correctly lined up, but then they get compressed by GR when it adds the color bar. I think this to fix this we'd need to take into account how much the color bar displaces the image, then displace the bottom images by that amount as well. @jheinen do you know how much that is?
I think, it's 10%: https://github.com/JuliaPlots/Plots.jl/blob/53510f3268e50a3a30e2e0029d15f8c530890bab/src/backends/gr.jl#L364
It would be nice if this could be fixed; it still is a quite annoying issue. In GR, the code
using Plots
p1 = plot(1:10, rand(10))
p2 = plot(4:14, rand(11))
p3 = heatmap(2:12, 2:12, rand(Float64, (10,10)))
l = @layout [a{.3h};b{.3h};c{.4h}]
p = plot(p1,p2,p3, layout=l, link=:x)
produces the attached image