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

I use the following for plotting with Plots.jl:

``````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
end
push!(all_predictions, trueValues)
push!(all_trueValues, predictions)
end

limits = [-0.7, 0.7]
trueRelationX, trueRelationY = collect(limits-1:limits+1), collect(limits-1:limits+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:

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)

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.

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

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

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

NB:
Julia 1.6.1 on Win10, Plots v1.15.2

1 Like

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!

1 Like