analistica/ex-7/plot.py

50 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python
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())
data = loadtxt(sys.stdin).reshape(n + m, d)
signal, noise = data[:n].T, data[n:].T
# rcParams['font.size'] = 8
# plt.figure(figsize=(3, 3))
plt.figure()
subplot(aspect='equal')
scatter(*signal, edgecolor='xkcd:charcoal',
c='xkcd:dark yellow', label='signal')
scatter(*noise, edgecolor='xkcd:charcoal',
c='xkcd:pale purple', label='noise')
line(-20*w, 20*w, c='xkcd:midnight blue', label='projection')
line(abs(w)-10*v, abs(w)+10*v, c='xkcd:scarlet', label='cut')
xlabel('x')
ylabel('y')
xlim(-1.5, 8)
ylim(-1.5, 8)
legend()
tight_layout()
# savefig('notes/images/7-fisher-plane.pdf')
#plt.figure(figsize=(3, 3))
plt.figure()
sig_proj = np.dot(w, signal)
noise_proj = np.dot(w, noise)
hist(sig_proj, color='xkcd:dark yellow', label='signal')
hist(noise_proj, color='xkcd:pale purple', label='noise')
axvline(cut, c='xkcd:scarlet', label='cut')
xlabel('projection line')
legend()
tight_layout()
# savefig('notes/images/7-fisher-proj.pdf')
show()