Copyright (C) 2020 Andreas Kloeckner
This notebook is best experienced when exported to a Python script and run from the command line.
import numpy as np
import numpy.linalg as la
from matplotlib.pyplot import (
clf, plot, show, xlim, ylim,
get_current_fig_manager, gca, draw, connect)
Run this cell to play with the node placement toy:
x_points = []
y_points = []
deg = [1]
def update_plot():
clf()
xlim([-1, 1])
ylim([-1.5, 1.5])
gca().set_autoscale_on(False)
plot(x_points, y_points, 'o')
if len(x_points) >= deg[0]+1:
eval_points = np.linspace(-1, 1, 500)
poly = np.poly1d(np.polyfit(
np.array(x_points),
np.array(y_points), deg[0]))
plot(eval_points, poly(eval_points), "-")
def click(event):
tb = get_current_fig_manager().toolbar
if event.button == 1 and event.inaxes and tb.mode == '':
x_points.append(event.xdata)
y_points.append(event.ydata)
if event.button == 3 and event.inaxes and tb.mode == '':
if len(x_points) >= deg[0]+2:
deg[0] += 1
update_plot()
draw()
update_plot()
connect('button_press_event', click)
show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-1-7e34ca5519e9> in <module> 31 draw() 32 ---> 33 update_plot() 34 connect('button_press_event', click) 35 show() <ipython-input-1-7e34ca5519e9> in update_plot() 4 5 def update_plot(): ----> 6 clf() 7 xlim([-1, 1]) 8 ylim([-1.5, 1.5]) NameError: name 'clf' is not defined