# Saved .png/.pdf shows title on top of plot

**URL:** https://discourse.julialang.org/t/saved-png-pdf-shows-title-on-top-of-plot/107650
**Category:** Visualization
**Tags:** plots
**Created:** [December 15, 2023, 9:18am UTC](https://discourse.julialang.org/t/saved-png-pdf-shows-title-on-top-of-plot/107650 "2023-12-15T09:18:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![peremato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peremato/32/29128_2.png) [@peremato](https://discourse.julialang.org/u/peremato)
#### Post date: [December 15, 2023, 9:18am UTC](https://discourse.julialang.org/t/saved-png-pdf-shows-title-on-top-of-plot/107650/1 "2023-12-15T09:18:57Z")

</div>

With Plots v1.39.0 on a MacOS arm 14.2, when saving plots (histograms) as .png or .pdf I get a different figure where the title is put on top of the plot. I am using the following code to plot:

```julia
    lay = @layout [°;°;°]
    plot(layout=lay, show=true, size=(1200,1000))
    for (i,l) in enumerate(fieldnames(eltype(new_dist)))
        stephist!(getfield.(new_dist, l), subplot=i, title="Δ$(l)", linewidth=2, label= i==1 ? "Gaudi" : nothing)
        stephist!(getfield.(old_dist, l), subplot=i, linewidth=2, label=i==1 ? "Marlin" : nothing)
    end

```

The result on the screen looks like this:

 ![Screenshot 2023-12-15 at 10.14.50](https://global.discourse-cdn.com/julialang/original/3X/5/6/56c544dd6fe06fc37c299f16b8e8c76e23d508e1.png)  
while the saved file is like this:  
 ![results](https://global.discourse-cdn.com/julialang/original/3X/c/d/cdcfed9facd8bc6ced6856e83ebd46891752cba2.png)

Is there anyway to avoid this? Thanks.

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [December 15, 2023, 12:10pm UTC](https://discourse.julialang.org/t/saved-png-pdf-shows-title-on-top-of-plot/107650/2 "2023-12-15T12:10:19Z")

</div>

Probably using the `margin` keyword, something like `plot!(margin = 0.5Plots.cm)`. (or `topmargin` and/or `bottommargin`).

---

<div class="post-metadata">

### Author: ![peremato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peremato/32/29128_2.png) [@peremato](https://discourse.julialang.org/u/peremato)
#### Post date: [December 15, 2023, 1:57pm UTC](https://discourse.julialang.org/t/saved-png-pdf-shows-title-on-top-of-plot/107650/3 "2023-12-15T13:57:25Z")

</div>

Thanks.  
Yes, it works much better. But there is still a difference between the saved figure and the on screen one.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [December 15, 2023, 2:00pm UTC](https://discourse.julialang.org/t/saved-png-pdf-shows-title-on-top-of-plot/107650/4 "2023-12-15T14:00:51Z")

</div>

seems like a potential bug in Plots.jl, can you reproduce it with smaller example?

---

<div class="post-metadata">

### Author: ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)
#### Post date: [December 15, 2023, 2:22pm UTC](https://discourse.julialang.org/t/saved-png-pdf-shows-title-on-top-of-plot/107650/5 "2023-12-15T14:22:50Z")

</div>

I think I agree that this is worth filing an Issue on GitHub over. Even better if you can include a MWE so it can be easily reproduced by somebody trying to fix it. My prior assumption going-in would that what is displayed by a `plot` call is the same as what gets saved by `savefig`, and I don’t see anything glaring in the docs [here](https://docs.juliaplots.org/latest/output/) or [here](https://docs.juliaplots.org/latest/api/#Plots.savefig-Tuple%7BPlots.Plot,%20Any%7D) that would caution me otherwise.

---

<div class="post-metadata">

### Author: ![peremato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peremato/32/29128_2.png) [@peremato](https://discourse.julialang.org/u/peremato)
#### Post date: [December 18, 2023, 2:45pm UTC](https://discourse.julialang.org/t/saved-png-pdf-shows-title-on-top-of-plot/107650/6 "2023-12-18T14:45:23Z")

</div>

Done. [[BUG] Saved .png/.pdf shows title on top of plot · Issue #4851 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/4851)
