Plot beyond gridlines

using WGLMakie


n = 500
x = 1:n
y = randn(n)

fig = Figure()
ax = Axis(
    fig[1,1],
    limits=(nothing, (-1.5, 1.5)),
    xgridcolor=:red,
    leftspinevisible=false,
    rightspinevisible=false,
    topspinevisible=false,
    bottomspinevisible=false,
)
scatter!(x,y)
fig

I want to plot points above and below the y-gridlines. That could be implemented in two ways:

  1. Extend the plotting space: plot points beyond the limits into the marginal space.
  2. Shorten the y-grid lines so they only go (-1.0, 1.0) instead of the full length of the limits, setting ygridlimits = (-1., 1.).

Is either of these possible?

Why not increase the limits themselves?

If I extend the limits, the y-gridlines will be extended too. I want to have scatter points beyond the vertical range of the red lines. So shortening the lines or plotting beyond the axis limits. The ygridlimits I mentioned is fictional; this intent may be too niche to merit support.

If it’s important to you that there are red lines ranging across certain values, I would just plot them directly and not work around the intrinsic behavior of grid lines

1 Like