plotjuliajulia-plots

Julia Plots.jl creates undesired white space when overlaying a plot() on top of a heatmap()


As the title says, when I do

julia> using Plots
julia> heatmap(rand(100,100))
julia> plot!(1:100,1:100,color=:white,lw=2,legend=false)

it produces: enter image description here

which creates undesired whitespace between the plot and the axis.

Is there a way to fix this?

I dont even know what causes the problem...


Solution

  • You need to either specify the x/y limits yourself or add widen=false to the plot command -- when you plot the line on top of the heatmap by default Julia tries to make sure you can fully see where the line starts and stops so this is where the extra padding is coming from.

    Code to get what you want (I think):

    heatmap(rand(100,100))
    plot!(1:100,1:100,color=:white,lw=2,legend=false,widen=false,tickdirection=:out)
    

    which results in this plot: sample julia heatmap without margin between axis and heatmap

    Note that I also added tickdirection=:out because I think when you have things running up against the axis the ticks are more readable that way.