Plots

Plotting functionality is provided via `Plots.jl and its Recipies.

Knots

For the knot functions inheriting from the abstract type Points plotting is supported. This defaults to 11 points.

using SparseGridsKit, Plots

p = plot(CCPoints([-3,3]))
plot!(CCPoints([-3,3]); n=21)
Example block output

Sparse Grids

Sparse grid points in a SparseGrid can be plotted. This has an optional arguement to select which indices are plotted which is useful in dimensions greater than 3.

miset = create_smolyak_miset(3,3)
sg = create_sparsegrid(miset)
p = plot(sg; targetdims=[3,2,1])
Example block output

Sparse Grid Approximations

Sparse grid approximations, consisting of function values and a polynomial approximation space can also be plotted.

f(x) = x[1]^5 + cos(x[2]) + abs(x[3])
f_on_sg = f.(get_grid_points(sg))

sga = SparseGridApproximation(sg,f_on_sg)
ssg = convert_to_spectral_approximation(sga)

p = plot(
    plot(sga; fill=true, title="fill=true"),
    plot(sga; targetdims=[2,3],title="targetdims"),
    plot(ssg; color=:turbo, fill=true, title=":turbo"),
    plot(ssg; seriestype=:surface, targetdims=[2,3], title="surface"),
    layout = (2,2)
)
Example block output

Function Reference

RecipesBase.apply_recipeMethod
f(p::Points; n = 11)

Recipe to plot scatter of knots and weights.

Arguments

  • p::Points: Points object.
  • n::Int: (Optional) Number of knots. Defaults to 11.
source
RecipesBase.apply_recipeMethod
f(sg::SparseGrid; targetdims=[1,2,3])

Recipe to convert sparse grid to set of x,y,z points in dimensions given by targetdims

Arguments

  • sg : Sparse grid
  • targetdims : (Optional) Cross section dimensions
source
RecipesBase.apply_recipeMethod
f(sga::SparseGridApproximation)
f(sg::SpectralSparseGridApproximation)

Recipe for plotting approximations based on sparse grids. For more than two dimensions it is a slice with the other parameters fixed at the midpoint.

source