# Plots.jl: Fill overlaps with x/y-axis

**URL:** <https://discourse.julialang.org/t/plots-jl-fill-overlaps-with-x-y-axis/62330>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [June 3, 2021, 12:36pm UTC](https://discourse.julialang.org/t/plots-jl-fill-overlaps-with-x-y-axis/62330 "2021-06-03T12:36:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scipham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scipham/32/24977_2.png) [@scipham](https://discourse.julialang.org/u/scipham)\
**Post date:** [June 3, 2021, 12:36pm UTC](https://discourse.julialang.org/t/plots-jl-fill-overlaps-with-x-y-axis/62330/1 "2021-06-03T12:36:30Z")

</div>

I use the following for plotting with Plots.jl:

```julia
using Plots
using HDF5
using Statistics

all_predictions = []
all_trueValues = []

h5open("3to12benchmark_corrected_r.dat", "r") do fid

for qn in 3:10

    predictions = []
    trueValues = []
    for runi in 1:3
        push!(predictions, read(fid[string("predictionArray",qn,"q", runi)]))
        push!(trueValues, read(fid[string("truePredictionArray", qn, "q", runi)]))
    end
    push!(all_predictions, trueValues)
    push!(all_trueValues, predictions)
end

limits = [-0.7, 0.7]
trueRelationX, trueRelationY = collect(limits[1]-1:limits[2]+1), collect(limits[1]-1:limits[2]+1)

num_measurements = 400
err = sqrt(1/num_measurements) *sqrt(3^3) #Chebyshev
    
p = [3,5,8,10]

#Using Subplots:
l = @layout grid(2,2){0.5w}
plt = plot( titlefont=5,
  labelfont=5,
  legend=false, 
  layout=l)

for (pi,pe) in enumerate(p)

    plot!(plt[pi], trueRelationX, trueRelationY .- err, 
    fillrange=trueRelationY .+ err, 
    fillalpha= 0.1, 
    fillcolor="blue", 
    linealpha=0.1,
    label="1-sigma",
    markersize=1,
    xlabel="True expectation",
    ylabel="Estimated expectation"

    )

    #Plot the linear y=x line for orientation
    plot!(plt[pi],trueRelationX, trueRelationY,
          linecolor=:black,
          linestyle=:dash,
          guidefontsize = 8
            )

    for runi in 1:3
        plot!(plt[pi], all_trueValues[pe .- 2][runi], all_predictions[pe .- 2][runi],
        seriestype = :scatter, 
        label="Iteration $runi",
        legend=false,
        title=["a", "b", "c", "d"][pi],
        xlim = [-1/sqrt(pi), 1/sqrt(pi)],
        ylim = [-1/sqrt(pi), 1/sqrt(pi)])
    end

end
    
display(plt)

end

```

My problem is that running this gives:

 ![Screenshot_2021-06-03 plot3to12benchmarkdatNotebook - Jupyter Notebook](https://global.discourse-cdn.com/julialang/original/3X/f/9/f9a867f790c839efe2ce1d1f3f30a5d074bece8c.png)

so the top-left figure gets a fill that shoots over the x-axis (and just doesn’t hit the y-axis). Can anyone say what I am possibly doing wrong here? Or is this probably a bug? I got this in similar plots already so I am not sure how common this is.  
(As there is no direct upload function here, the code runs directly with this datafile: [3to12benchmark\_corrected\_r.dat - Google Drive](https://drive.google.com/file/d/1_AGb4sLKh4h9mVeKVBalVzqak3je7i2U/view?usp=sharing))

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 3, 2021, 3:28pm UTC](https://discourse.julialang.org/t/plots-jl-fill-overlaps-with-x-y-axis/62330/2 "2021-06-03T15:28:30Z")

</div>

Is this issue fixed if you enforce tight plots with the argument `widen=false`?

_ **NB:** _  
_Better if you can provide a MWE with input data._

---

<div class="post-metadata">

**Author:** ![scipham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scipham/32/24977_2.png) [@scipham](https://discourse.julialang.org/u/scipham)\
**Post date:** [June 3, 2021, 4:32pm UTC](https://discourse.julialang.org/t/plots-jl-fill-overlaps-with-x-y-axis/62330/3 "2021-06-03T16:32:21Z")

</div>

Thanks @rafael.guerra . No, but it’s closer.

 ![Screenshot_2021-06-03 plot3to12benchmarkdatNotebook - Jupyter Notebook(1)](https://global.discourse-cdn.com/julialang/original/3X/3/5/354b6497cf74304e734daae3b3ce05a37e6a1ce3.png)

I indeed wanted to provide the .dat file but didn’t see a way to upload it here. So maybe this way: [3to12benchmark\_corrected\_r.dat - Google Drive](https://drive.google.com/file/d/1_AGb4sLKh4h9mVeKVBalVzqak3je7i2U/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 3, 2021, 6:30pm UTC](https://discourse.julialang.org/t/plots-jl-fill-overlaps-with-x-y-axis/62330/4 "2021-06-03T18:30:26Z")

</div>

@scipham, tested your code here, added an earlier `end` to the `h5open` command, and did not observe any leakage using Plots gr() back-end:

 ![Plots_gr_fillrange_no_leaks](https://global.discourse-cdn.com/julialang/original/3X/c/f/cfb24f2d1cfe8e459a943d32bb4c72a0f0f284d2.png)

**NB:**  
_Julia 1.6.1 on Win10, Plots v1.15.2_

---

<div class="post-metadata">

**Author:** ![scipham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scipham/32/24977_2.png) [@scipham](https://discourse.julialang.org/u/scipham)\
**Post date:** [June 4, 2021, 7:26am UTC](https://discourse.julialang.org/t/plots-jl-fill-overlaps-with-x-y-axis/62330/5 "2021-06-04T07:26:26Z")

</div>

Ah, yes in REPL it now works as well. It seems I’ve been relying too much on Jupyter notebooks once again. Now I know again why I didn’t like them 😉 Thanks a lot for helping out!
