ex-7: improve plot by adding the separatrix
This commit is contained in:
parent
17f702b8d0
commit
1bcbf1cfe6
12
ex-7/plot.py
12
ex-7/plot.py
@ -3,7 +3,12 @@
|
||||
from pylab import *
|
||||
import sys
|
||||
|
||||
def line(x, y, **args):
|
||||
'''line between two points x,y'''
|
||||
plot([x[0], y[0]], [x[1], y[1]], **args)
|
||||
|
||||
w = loadtxt(sys.stdin, max_rows=2)
|
||||
v = array([[0, -1], [1, 0]]) @ w
|
||||
cut = float(input())
|
||||
|
||||
n, m, d = map(int, input().split())
|
||||
@ -11,10 +16,13 @@ data = loadtxt(sys.stdin).reshape(n + m, d)
|
||||
signal, noise = data[:n].T, data[n:].T
|
||||
|
||||
figure()
|
||||
subplot(aspect='equal')
|
||||
scatter(*signal, c='xkcd:grey blue', label='signal')
|
||||
scatter(*noise, c='xkcd:baby blue', label='noise')
|
||||
scatter(*(cut * w/np.dot(w,w)), c='red')
|
||||
arrow(*(-abs(w)), *4*abs(w))
|
||||
line(-20*w, 20*w, c='xkcd:blue', label='projection')
|
||||
line(w-10*v, w+10*v, c='xkcd:red', label='cut')
|
||||
xlim(-1.5, 8)
|
||||
ylim(-1.5, 8)
|
||||
legend()
|
||||
|
||||
figure()
|
||||
|
Loading…
Reference in New Issue
Block a user