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)
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])
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)
)
Function Reference
RecipesBase.apply_recipe
— Methodf(p::Points; n = 11)
Recipe to plot scatter of knots and weights.
Arguments
p::Points
:Points
object.n::Int
: (Optional) Number of knots. Defaults to11
.
RecipesBase.apply_recipe
— Methodf(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 gridtargetdims
: (Optional) Cross section dimensions
RecipesBase.apply_recipe
— Methodf(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.