{ } Raw JSON

bundles / papyri latest / papyri / examples / example2

function

papyri.examples:example2

source: /papyri/examples.py:302

Signature

def example2() → None

Examples

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import UnivariateSpline
✓
x = np.linspace(-3, 3, 50)
y = np.exp(-(x ** 2)) + 0.1 * np.random.randn(50)
✓
plt.plot(x, y, "ro", ms=5)
✗
[<matplotlib.lines.Line2D object at 0x7f4c9588cad0>]
Use the default value for the smoothing parameter:
spl = UnivariateSpline(x, y)
xs = np.linspace(-3, 3, 1000)
✓
plt.plot(xs, spl(xs), "g", lw=3)
✗
[<matplotlib.lines.Line2D object at 0x7f4c9588cd70>]
Manually change the amount of smoothing:
spl.set_smoothing_factor(0.5)
✓
plt.plot(xs, spl(xs), "b", lw=3)
✗
[<matplotlib.lines.Line2D object at 0x7f4c9588cec0>]
plt.show()
✓
fig-8350fc0de20abaa8.png

Aliases

  • papyri.examples.example2