Matplotlib – python – click and add Gaussian peaks

# click and add Gaussian peaks

import matplotlib.pyplot as plt
import numpy as np
import pdb
import sys
from multi_gauss import multiGauss as Gauss

x = np.linspace(0, 2*3.14, 100)
guess = [100, 3, 0.5]
y = Gauss(x, *guess)
y = np.array(y)
pts = []

def onPress(event):
    print(event.xdata, event.ydata)
    for pt in pts:
        x = pt.get_xdata()
        y = pt.get_ydata()
        ax.plot(x, y)
    pt, = ax.plot(x, y + 5)

fig, ax = plt.subplots()
pt1, = ax.plot(x, y)
pt2, = ax.plot(x, y + 2)
pts = [pt1, pt2]
pt1.figure.canvas.mpl_connect('button_press_event', onPress)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s