every function in this library should work with any interactive matplotlib backend. Although the functions from mpl_interactions.jupyter
assume that you are in a notebook context in order to display the sliders.
# NBVAL_SKIP
%matplotlib qt5
import numpy as np
import matplotlib.pyplot as plt
from mpl_interactions import interactive_plot
The below cell will display the sliders in the notebook but a separate matplotlib window will pop up. An important caveat is that the performance of interactive_plot
seems to be significantly worse with a non-ipympl backend.
x = np.linspace(0, np.pi, 100)
τ = np.linspace(1, 10, 100)
β = np.linspace(1, 10, 100)
def f(x, τ, β):
return np.sin(x * τ) * x ** β
fig, ax = plt.subplots()
controls = interactive_plot(x, f, τ=τ, β=β)
mpl_interactions.generic
contains functions that will work in any matplotlib context. So for example the below code will work in the notebook or from a script
from mpl_interactions.generic import heatmap_slicer
x = np.linspace(0, np.pi, 100)
y = np.linspace(0, 10, 200)
X, Y = np.meshgrid(x, y)
data1 = np.sin(X) + np.exp(np.cos(Y))
data2 = np.cos(X) + np.exp(np.sin(Y))
fig, axes = heatmap_slicer(
x,
y,
(data1, data2),
slices="both",
heatmap_names=("dataset 1", "dataset 2"),
labels=("Some wild X variable", "Y axis"),
interaction_type="move",
)