# Plotting only the contents of a plot/heatmap and hiding everything else using Plots.jl

**URL:** <https://discourse.julialang.org/t/plotting-only-the-contents-of-a-plot-heatmap-and-hiding-everything-else-using-plots-jl/104469>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [October 1, 2023, 3:14pm UTC](https://discourse.julialang.org/t/plotting-only-the-contents-of-a-plot-heatmap-and-hiding-everything-else-using-plots-jl/104469 "2023-10-01T15:14:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferrolho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ferrolho/32/213665_2.png) [@ferrolho](https://discourse.julialang.org/u/ferrolho)\
**Post date:** [October 1, 2023, 3:14pm UTC](https://discourse.julialang.org/t/plotting-only-the-contents-of-a-plot-heatmap-and-hiding-everything-else-using-plots-jl/104469/1 "2023-10-01T15:14:56Z")

</div>

Hi! I would like to plot only the very contents of a plot (a heatmap in this case) using Plots.jl.

I’ve set the aspect ratio to 1:1, hidden the axes, hidden the color bar, set the margins to zero, and set the image size to match the size of the actual heatmap. However, I still get a white border around the plot, and the size of the plot is not exactly what I set it to be.

Here is a sample code:

```julia
using Plots
using Plots.PlotMeasures

const N = 400
const xs = 1:N
const ys = 1:N
const values = rand(N, N)

heatmap(
    xs, ys, values,
    aspect_ratio=:equal, # 1:1 aspect ratio
    axis=([], false), # Hide axes
    cbar=false, # Hide color bar
    margins=0px, # Hide margins
    size=(N, N), # Figure size
)

savefig("plot.png")

```

![plot](https://global.discourse-cdn.com/julialang/original/3X/6/1/61bd95bb85cb6b2ce93a8e932a9b751007fd9aae.png)

Notice the white border around the plot and the `399 × 400` dimensions instead of `400 × 400`.

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [October 11, 2023, 6:17pm UTC](https://discourse.julialang.org/t/plotting-only-the-contents-of-a-plot-heatmap-and-hiding-everything-else-using-plots-jl/104469/2 "2023-10-11T18:17:48Z")

</div>

There’s a built-in margin of 2 (mm?) with GR. (To be fixed… someday.) Try using a negative margin.
