While I was working on an example for you, I realized my problem can be solved simply by making those parameters global.

An simple example is shown below, the idea was to send the variable “factor” along with the 2D array.

Example -----------------------------------

```
import numpy as np
import matplotlib.pyplot as plt
import mpl_interactions.ipyplot as ipl
import mpl_interactions.ipyplot as iplt
def Gauss_2D(x, y, A, x0, y0, std):
g2d= A * np.exp( -0.5*((x-x0)/std)**2 -.5*((y-y0)/std)**2)
return g2d
# p1: baseline
dx = 100
x = np.linspace(-(dx+1)//2, (dx+1)//2, dx)
y = np.linspace(-(dx+1)//2, (dx+1)//2, dx)
xx, yy = np.meshgrid(x, y)
p1 = np.zeros_like(xx, dtype = np.uint8)
p2 = np.zeros_like(xx, dtype = np.uint8)
factor =1.
# Interactive
def chg_mix(s1, s2):
global factor
p1 = Gauss_2D(xx,yy, 300, 0, 0, 50)
p2 = Gauss_2D(xx,yy, 50, s1, s2, 10)
combo = np.zeros_like(p1, dtype = float)
combo = p1 + p2
print(f'combo max before scaling: {combo.max():.1f}')
factor = 255./ combo.max()
combo *= factor
print(f'scaling factor: {factor:.2f}, combo max after scaling: {combo.max():.1f}')
#return (combo, factor)
return combo.astype(dtype=np.uint8)
def pp(s1, s2):
global factor
p3 = (Gauss_2D(xx,yy, 300, 0, 0, 50)+Gauss_2D(xx,yy, 50, s1, s2, 10))*factor
print(f'p3 max: {p3.max()}')
return p3[dx//2, :]
# Plotting Final results
s1=np.arange(0.,50.)
s2=np.arange(0.,50.)
plt.figure(figsize=(10,5))
ax1=plt.subplot(121)
ctrl = iplt.imshow(chg_mix, ax=ax1,
s1=s1,
s2=s2,
)
ax2=plt.subplot(122)
iplt.plot(pp, controls = ctrl, ax=ax2)
plt.show()
plt.tight_layout()
```