Plotting spline bases#
This example demonstrates how to plot the spline bases of the library.
Imports#
Import the necessary libraries and utility functions to define spline bases.
import numpy as np
import matplotlib.pyplot as plt
from splineops.bases.utils import basis_map, create_basis
Function to plot bases#
Define a helper function to plot spline bases.
def plot_bases(names, x_values, title):
plt.figure(figsize=(12, 6))
for name in names:
# Convert the base name to a more readable format
if name == "keys":
# Special case for Keys spline: no degree in the label
readable_name = "Keys Spline"
else:
name_parts = name.split("-")
readable_name = f"{name_parts[0][:-1]} degree {name_parts[0][-1]}"
# Evaluate the basis function
y_values = create_basis(name).eval(x_values)
plt.plot(x_values, y_values, label=readable_name)
plt.title(title)
plt.xlabel("x")
plt.ylabel("y")
plt.grid(True)
plt.legend()
plt.show()
Spline bases evaluation and plotting#
Define the x range and plot the spline bases in figures.
x_values = np.linspace(-3, 3, 1000)
Combined plot for B-spline degrees 0 to 9#
Combined plot for O-MOMS degrees 0 to 5#
Plot for Keys basis function#
Total running time of the script: (0 minutes 0.266 seconds)