Rotate grid in plots

This is probably not the most elegant, but it does the trick

θ = 0.2
N = 11
xs = range(-10, 10, length=N)
ys = range(-10, 10, length=N)
us = ones(N)

Q = [cos(θ) sin(θ) ; -sin(θ) cos(θ)]  # rotation matrix

plot()
    
for n=1:N
    xline = [xs ;; ys[n]*us]  # a horizontal line
    yline = [xs[n]*us ;; ys]  # a vertical line
    xlineQ = xline*Q          # rotated horizontal line
    ylineQ = yline*Q          # rotated vertical line
    plot!(xlineQ[:,1], xlineQ[:,2], color=:black, label="")
    plot!(ylineQ[:,1], ylineQ[:,2], color=:black, label="")
end
plot!(aspect_ratio=:equal)

rotategrid

3 Likes