How to produce a 3D polar plot in Makie?

I wonder how to produce plots like the one below (a 3D array factor) using Makie?
image

If this is not possible in Makie, any packages that support this? Thanks a lot.

1 Like

I would not call this a polar plot because it is not using a polar axis. You can plot the mesh you have there like any other, even if its generation involves a polar coordinate system.

To expand on the answer already given, Check out the beautiful makie gallery for examples.

Here’s a quick-and-dirty attempt I just threw together with Makie that you could play around with:

using GLMakie

AF(θ,φ) = abs( sinc(2θ) )

# Coordinate space to be modeled
φs = range(0, 2π, length=361)   # angle within xy-plane relative to +x
θs = range(0, π, length=181)    # angle relative to +z
angles = [(φ,θ) for φ in φs, θ in θs]

# Get radius (the Array Factor) at each angle
rs = [AF(θ, φ) for (φ,θ) in angles]   # radius = AF(θ,φ)

# Convert this data to a 2D mesh
spherical_mesh = [(r,φ,θ) for (r,(φ,θ)) in zip(rs,angles)]

# Convert spherical coordinates to rectangular coordinates
xs = [r*sin(θ)*cos(φ) for (r,φ,θ) in spherical_mesh]
ys = [r*sin(θ)*sin(φ) for (r,φ,θ) in spherical_mesh]
zs = [r*cos(θ)        for (r,φ,θ) in spherical_mesh]

# Plot
fig = Figure()
ax = Axis3(fig[1,1])
surface!(ax, xs, ys, zs)
save("antennapattern.png", fig)

antennapattern

Not exactly the prettiest pattern, but you get the idea.

5 Likes

Perhaps, it should be called a 3D spherical plot?
see: SphericalPlot3D—Wolfram Language Documentation

1 Like

Kind of a technicality, but I think what @jules was trying to say is that in Makie a PolarAxis specifically denotes an (r,theta) style of plot vs an Axis (2D x,y) or Axis3 (3D x,y,z). The example provided in the OP is technically a surface plot on an Axis3.

In common usage, though, it would be nice to have some recipe like sphericalplot(f) where f(theta,phi) is defined.

3 Likes

Plot of the surface r=1+2cos(2\varphi) with PlotlyJS:

using PlotlyJS
φ=range(0, π, 150)
θ=range(0,2π, 150)
x = @. cos(θ)*((1+2*cos(2*φ'))*sin(φ')) 
y = @. sin(θ)*((1+2*cos(2*φ'))*sin(φ'))
z = ones(150) *(1 .+2*cos.(2*φ')) .*cos.(φ')
pl=Plot(surface(x=x, y=y, z=z, colorbar=attr(thickness=24, len=0.75)), 
        Layout(width=500, height=500, font_size=11, 
               scene_camera_eye=attr(x=2.2, y=2.2, z=1.2)))

spherical-plot-math

2 Likes

Thank you for all the suggestions! especially @mike.ingold and @empet for the demo, I learned a lot.

1 Like