# Plots.jl | Heatmap legend is cut off or lays on top of the colorbar ticks

**URL:** <https://discourse.julialang.org/t/plots-jl-heatmap-legend-is-cut-off-or-lays-on-top-of-the-colorbar-ticks/107329>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 8, 2023, 2:05pm UTC](https://discourse.julialang.org/t/plots-jl-heatmap-legend-is-cut-off-or-lays-on-top-of-the-colorbar-ticks/107329 "2023-12-08T14:05:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lenardj](https://avatars.discourse-cdn.com/v4/letter/l/f04885/32.png) [@lenardj](https://discourse.julialang.org/u/lenardj)\
**Post date:** [December 8, 2023, 2:05pm UTC](https://discourse.julialang.org/t/plots-jl-heatmap-legend-is-cut-off-or-lays-on-top-of-the-colorbar-ticks/107329/1 "2023-12-08T14:05:16Z")

</div>

I am using the heatmap function in Plots.jl to plot densities in a plane. The colorbar should have a legend with an explanation “…”. I use the following code:

Heatmap = heatmap!(x,y,HeatmapData, c = :thermal,xlabel = “Local Time [h]”,ylabel = “Latitude [°]”,zlabel = “Density [particles / cm^3]”)

heatmap(titlefont=font(12,“Helvetica”),guidefont=font(12,“Helvetica”), labelfont=font(12,“Helvetica”), xtickfontsize=10,ytickfontsize=10,legendfont=(12,“Helvetica”),xticks=[0, 6, 12, 18, 24])

The plot looks like expected but the ticks of the colorbar are cut-off and so is the colorbar label. If I scale the numbers down it also occurs that the label lays on top of the ticks.

 ![Heatmap_Density_Layer1](https://global.discourse-cdn.com/julialang/original/3X/2/c/2cddb42b81e1c1ff80a95f2cf5bafa770ffb1262.png)

I appreciate your help!

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [December 8, 2023, 4:44pm UTC](https://discourse.julialang.org/t/plots-jl-heatmap-legend-is-cut-off-or-lays-on-top-of-the-colorbar-ticks/107329/2 "2023-12-08T16:44:27Z")

</div>

Try supplying a margin as a keyword argument, e.g. `rightmargin=5Plots.mm` .

One might think that Plots shoild handle this automatically, but from my understanding, writing a program which figures out how much space a piece of text will take is one of the hardest problems in CS.
