From bbb5bf13bf8ac235d1bc7e2d312bc0d6f6de04c6 Mon Sep 17 00:00:00 2001 From: Hannes Kuchelmeister Date: Tue, 4 May 2021 11:10:22 +0200 Subject: [PATCH] plot parties based on mp avergae position #9 --- VotingAnalysis.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/VotingAnalysis.py b/VotingAnalysis.py index aee1031..61e29b1 100644 --- a/VotingAnalysis.py +++ b/VotingAnalysis.py @@ -219,9 +219,30 @@ ys, xs = np.unravel_index(np.argmax(X, axis=1), (h, w)) ys_disp = ys + np.random.rand(ys.shape[0]) xs_disp = xs + np.random.rand(xs.shape[0]) -party_index_mapping, party_affiliation_numeric = np.unique(data[:,1], return_inverse=True) +party_index_mapping, party_ids = np.unique(data[:,1], return_inverse=True) + +plot_mps(fig, ax, xs_disp, ys_disp, data[:,0] + " (" + data[:,1] + ")", party_ids) +plt.show() + +party_count = np.zeros(party_index_mapping.shape[0]) +party_xs = np.zeros(party_index_mapping.shape[0]) +party_ys = np.zeros(party_index_mapping.shape[0]) +for x, y, party_id in zip(xs, ys, party_ids): + party_xs[party_id] += x + party_ys[party_id] += y + party_count[party_id] += 1 + +party_xs /= party_count +party_ys /= party_count + +plt.figure() +plt.scatter(party_xs, party_ys) + +# plotting labels +offset = 0.01 +for x,y, party in zip(party_xs, party_ys, party_index_mapping): + plt.text(x + offset, y + offset, party) -plot_mps(fig, ax, ys_disp, xs_disp, data[:,0] + " (" + data[:,1] + ")", party_affiliation_numeric) plt.show() #Simple SOFM for UK