Plotting data on Spheres

On a sphere we can plot points and tangent vectors with the default scatter and arrows3d. To start a plot on a manifold, there is usually a manifoldplot function, here sphereplot to set up the figure and add here for example the sphere the data lives on.

The 1D Sphere $๐•Š^1$

For the one-dimensional sphere, we obtain unit vectors in $โ„^2$ or in other words points on the circle.

using Manifolds, ManifoldMakie, GLMakie

M = Manifolds.Sphere(1)
# Since S2 is the default case and its color is white, set S1 surface/boundary color
fig, ax, pl = sphereplot(M; surfacecolor=:gray)

p = [1.0, 0.0]
q = [1/sqrt(2), -1/sqrt(2)]
r = [1/sqrt(2), 1/sqrt(2)]
pts = shortest_geodesic(M, p, q, 0:0.05:1.0)
vecs = [log(M, s, r) for s in pts]

arrows2d!(ax, M, pts, vecs; color = :blue)
scatter!(ax, M, pts; color = :green, markersize = 16)
scatter!(ax, M, [r,]; color = :orange, markersize = 16)
fig
Example block output

The 2D Sphere $๐•Š^2$

On a sphere we can plot points and tangent vectors with the default scatter and arrows3d. To start a plot on a manifold, there is usually a manifoldplot function, here sphereplot to set up the figure and add here for example the sphere the data lives on.

using Manifolds, ManifoldMakie, GLMakie

M = Manifolds.Sphere(2)
fig, ax, pl = sphereplot(M)

p = [0.0, 0.0, 1.0]
q = [0.0, 1/sqrt(2), -1/sqrt(2)]
r = [1/sqrt(2), 0.0, 1/sqrt(2)]
pts = shortest_geodesic(M, p, q, 0:0.05:1.0)
vecs = [log(M, s, r) for s in pts]

arrows3d!(
    ax, M, pts, vecs; color = :blue,
    minshaftlength = 0, shaftlength=.99, shaftradius = 0.004, tipradius = 0.016, tiplength = 0.1,
)
scatter!(ax, M, pts; color = :green, markersize = 16)
scatter!(ax, M, [r,]; color = :orange, markersize = 16)
fig
Example block output

We can also use the geodesics and scattergeodesics functions here.

using Manifolds, ManifoldMakie, GLMakie

M = Manifolds.Sphere(2)
fig, ax, pl = sphereplot(M)

p1, p2, p3 = [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]
p1b, p2b, = [1/sqrt(2), 0, 1/sqrt(2)], [0, 1/sqrt(2), 1/sqrt(2)]

geodesics!(ax, M, Point3f.([p1, p2, p3]); closed = true, color = :green, linewidth = 3)
scattergeodesics!(ax, M, Point3f.([p1b, p2b, p3]); closed = true, color = :blue, linewidth = 2, markersize = 12)
fig
Example block output

A sphere-valued image

When dealing with a 2D array of data living on the sphere, for example a dataset of wind field directions, we can plot this as

using Manifolds, ManifoldMakie, ManoptExamples, GLMakie

M = Manifolds.Sphere(2)
img = ManoptExamples.artificial_S2_whirl_image()
fig, ax, pl = image(M, img)
fig
Example block output

Function reference

ManifoldMakie.sphereplot โ€” Function
sphereplot(::Manifolds.Sphere{โ„, Manifolds.TypeParameter{Tuple{n}}}; kwargs...)

Draw the Sphere(n), $n=1,2$ as a (transparent) surface with an overlaid wireframe.

This can be combined with

Examples

fig, ax, p = sphereplot(Manifolds.Sphere(2))

for the 2-sphere $๐•Š^2$ embedded in $โ„^3$

fig, ax, p = sphereplot(Manifolds.Sphere(1))

for the cyclic data on $๐•Š^1$ embedded in $โ„^2$

Plot type

The plot type alias for the sphereplot function is SpherePlot.

Attributes

clip_planes = @inherit clip_planes automatic โ€” Clip planes offer a way to do clipping in 3D space. You can set a Vector of up to 8 Plane3f planes here, behind which plots will be clipped (i.e. become invisible). By default clip planes are inherited from the parent plot or scene. You can remove parent clip_planes by passing Plane3f[].

depth_shift = 0.0 โ€” Adjusts the depth value of a plot after all other transformations, i.e. in clip space, where -1 <= depth <= 1. This only applies to GLMakie and WGLMakie and can be used to adjust render order (like a tunable overdraw).

fxaa = true โ€” Adjusts whether the plot is rendered with fxaa (fast approximate anti-aliasing, GLMakie only). Note that some plots implement a better native anti-aliasing solution (scatter, text, lines). For them fxaa = true generally lowers quality. Plots that show smoothly interpolated data (e.g. image, surface) may also degrade in quality as fxaa = true can cause blurring.

inspectable = @inherit inspectable โ€” Sets whether this plot should be seen by DataInspector. The default depends on the theme of the parent scene.

inspector_clear = automatic โ€” Sets a callback function (inspector, plot) -> ... for cleaning up custom indicators in DataInspector.

inspector_hover = automatic โ€” Sets a callback function (inspector, plot, index) -> ... which replaces the default show_data methods.

inspector_label = automatic โ€” Sets a callback function (plot, index, position) -> string which replaces the default label generated by DataInspector.

model = automatic โ€” Sets a model matrix for the plot. This overrides adjustments made with translate!, rotate! and scale!.

overdraw = false โ€” Controls if the plot will draw over other plots. This specifically means ignoring depth checks in GL backends

space = :data โ€” Sets the transformation space for box encompassing the plot. See Makie.spaces() for possible inputs.

ssao = false โ€” Adjusts whether the plot is rendered with ssao (screen space ambient occlusion). Note that this only makes sense in 3D plots and is only applicable with fxaa = true.

surfacealpha = 0.33 โ€” Surface alpha (0 = transparent, 1 = opaque).

surfaceboundary = 2 โ€” thickness of the boundary surface (only $๐•Š^1$)

surfacecolor = :white โ€” Solid color of the surface ($๐•Š^2$) or boundary ($๐•Š^1$).

transformation = :automatic โ€” Controls the inheritance or directly sets the transformations of a plot. Transformations include the transform function and model matrix as generated by translate!(...), scale!(...) and rotate!(...). They can be set directly by passing a Transformation() object or inherited from the parent plot or scene. Inheritance options include:

  • :automatic: Inherit transformations if the parent and child space is compatible
  • :inherit: Inherit transformations
  • :inherit_model: Inherit only model transformations
  • :inherit_transform_func: Inherit only the transform function
  • :nothing: Inherit neither, fully disconnecting the child's transformations from the parent

Another option is to pass arguments to the transform!() function which then get applied to the plot. For example transformation = (:xz, 1.0) which rotates the xy plane to the xz plane and translates by 1.0. For this inheritance defaults to :automatic but can also be set through e.g. (:nothing, (:xz, 1.0)).

transparency = false โ€” Adjusts how the plot deals with transparency. In GLMakie transparency = true results in using Order Independent Transparency.

visible = true โ€” Controls whether the plot gets rendered or not.

wirecolor = (:lightsteelblue, 0.4) โ€” Color of the wireframe lines drawn on top of the surface ($๐•Š^2$).

wires = 24 โ€” Tessellation resolution (segments of the wireframe in every direction, $๐•Š^2$).

wirewidth = 0.5 โ€” linewidth of the wire ($๐•Š^2$)

source
ManifoldMakie.spheredataimage โ€” Function
image(M, x, y, image)
image(M, image)

as an alias for

spheredataimage(M, x, y, image)
spheredataimage(M, image)

Plots an image on a rectangle bounded by x and y (defaults to size of image).

Plot type

The plot type alias for the spheredataimage function is SphereDataImage.

Attributes

alpha = 1.0 โ€” The alpha value of the colormap or color attribute. Multiple alphas like in plot(alpha=0.2, color=(:red, 0.5)), will get multiplied.

clip_planes = @inherit clip_planes automatic โ€” Clip planes offer a way to do clipping in 3D space. You can set a Vector of up to 8 Plane3f planes here, behind which plots will be clipped (i.e. become invisible). By default clip planes are inherited from the parent plot or scene. You can remove parent clip_planes by passing Plane3f[].

colormap = :viridis โ€” Sets the colormap that is sampled for numeric colors. PlotUtils.cgrad(...), Makie.Reverse(any_colormap) can be used as well, or any symbol from ColorBrewer or PlotUtils. To see all available color gradients, you can call Makie.available_gradients().

colorrange = automatic โ€” The values representing the start and end points of colormap.

colorscale = identity โ€” The color transform function. Can be any function, but only works well together with Colorbar for identity, log, log2, log10, sqrt, logit, Makie.pseudolog10, Makie.Symlog10, Makie.AsinhScale, Makie.SinhScale, Makie.LogScale, Makie.LuptonAsinhScale, and Makie.PowerScale.

depth_shift = 0.0 โ€” Adjusts the depth value of a plot after all other transformations, i.e. in clip space, where -1 <= depth <= 1. This only applies to GLMakie and WGLMakie and can be used to adjust render order (like a tunable overdraw).

fxaa = true โ€” Adjusts whether the plot is rendered with fxaa (fast approximate anti-aliasing, GLMakie only). Note that some plots implement a better native anti-aliasing solution (scatter, text, lines). For them fxaa = true generally lowers quality. Plots that show smoothly interpolated data (e.g. image, surface) may also degrade in quality as fxaa = true can cause blurring.

highclip = automatic โ€” The color for any value above the colorrange.

inspectable = @inherit inspectable โ€” Sets whether this plot should be seen by DataInspector. The default depends on the theme of the parent scene.

inspector_clear = automatic โ€” Sets a callback function (inspector, plot) -> ... for cleaning up custom indicators in DataInspector.

inspector_hover = automatic โ€” Sets a callback function (inspector, plot, index) -> ... which replaces the default show_data methods.

inspector_label = automatic โ€” Sets a callback function (plot, index, position) -> string which replaces the default label generated by DataInspector.

lowclip = automatic โ€” The color for any value below the colorrange.

model = automatic โ€” Sets a model matrix for the plot. This overrides adjustments made with translate!, rotate! and scale!.

nan_color = :transparent โ€” The color for NaN values.

overdraw = false โ€” Controls if the plot will draw over other plots. This specifically means ignoring depth checks in GL backends

space = :data โ€” Sets the transformation space for box encompassing the plot. See Makie.spaces() for possible inputs.

ssao = false โ€” Adjusts whether the plot is rendered with ssao (screen space ambient occlusion). Note that this only makes sense in 3D plots and is only applicable with fxaa = true.

transformation = :automatic โ€” Controls the inheritance or directly sets the transformations of a plot. Transformations include the transform function and model matrix as generated by translate!(...), scale!(...) and rotate!(...). They can be set directly by passing a Transformation() object or inherited from the parent plot or scene. Inheritance options include:

  • :automatic: Inherit transformations if the parent and child space is compatible
  • :inherit: Inherit transformations
  • :inherit_model: Inherit only model transformations
  • :inherit_transform_func: Inherit only the transform function
  • :nothing: Inherit neither, fully disconnecting the child's transformations from the parent

Another option is to pass arguments to the transform!() function which then get applied to the plot. For example transformation = (:xz, 1.0) which rotates the xy plane to the xz plane and translates by 1.0. For this inheritance defaults to :automatic but can also be set through e.g. (:nothing, (:xz, 1.0)).

transparency = false โ€” Adjusts how the plot deals with transparency. In GLMakie transparency = true results in using Order Independent Transparency.

visible = true โ€” Controls whether the plot gets rendered or not.

source