Plot lines and markers beyond the limits of the axes?

Is it possible? I tried to search for information but I’m not sure what key words I should use . . .

In the following example, the first and last markers are cut in half or quarter at the left and right edges of the frame of the graph:

using Plots
a = vcat(1, rand(Float64, 10))
plot(0:10, a; xlim=(0,10), ylim=(0,1), marker=:circle, markersize=5)

I’d like the circles to be fully displayed.

Also, I sometimes want to extend the lines and markers beyond the edges of the frame. [It’s a bit ugly but a bit more informative than not showing those datapoints when only a few datapoints fall a little beyond the round number axis limits. Suppose, for example, 97 of the 100 values fall between 0 and 1 and the remaining 3 are like 1.06; then you might choose to set the y axis limit to [0,1] and let the three points shown beyond the upper edge of the frame.]

In this case, using frame=:origin and adequate xlim, ylim, can help:

using Plots; gr()
x, y = 0:10, vcat(1, rand(Float64, 10))
ex, ey = extrema(x), extrema(y)
ϵ₁, ϵ₂ = 0.03*(ex[2] - ex[1]), 0.03*(ey[2] - ey[1])
plot(x, y; frame=:origin, xlim=(-ϵ₁,10+ϵ₁), ylim=(-ϵ₂,1+ϵ₂), m=:circle, ms=5)

The above code is displayed in the left panel, while the default display is on the right:

1 Like

Thank you for your help! You made me realize that xlim and ylim refer to the data, not the axes. I’ve also learned the frame attribute. . . .

. . . But, your

In this case

has made me wonder . . . As a test, I shifted the data upward such that the data range is [1, 2]. See the sample code and the image below. We then lose the x axis.

If the frame attribute could specify the exact frame, like, say, frame = ( (xmin, ymin), (xmax, ymax)), this problem might be solved . . . ?

Sample code: You can shift the ranges of x and y:

using Plots
#ymin = 0; ymax = 1; ydel = 0.1 # <- Works fine.
ymin = 1; ymax = ymin + 1; ydel = 0.1
xmin = 0; xmax = 10; xdel = 1
a = vcat(ymax, rand(Float64, 10) .+ ymin)
ylim = (ymin - ydel, ymax + ydel)
xlim = (xmin - xdel, xmax + xdel)
plot(xmin:xmax, a; xlim=xlim, ylim=ylim,
     frame=:origin, marker=:circle, markersize=5)

Yes, that’s my concern. Perhaps you could automate a custom axis function inspired by the solution presented in this post.