mirror of
https://github.com/13hannes11/UU_NCML_Project.git
synced 2024-09-03 20:50:59 +02:00
Legends are set to party plots
This commit is contained in:
@@ -179,13 +179,11 @@ def calc_party_pos(members_of_parliament, party_affiliation):
|
|||||||
|
|
||||||
return pd.DataFrame(data=party_pos, index=party_index_mapping)
|
return pd.DataFrame(data=party_pos, index=party_index_mapping)
|
||||||
def plot_parties(parties, randomize_positions=False, new_plot=True):
|
def plot_parties(parties, randomize_positions=False, new_plot=True):
|
||||||
cmap = plt.cm.RdYlGn
|
|
||||||
|
|
||||||
party_index_mapping = parties.index
|
party_index_mapping = parties.index
|
||||||
|
|
||||||
if new_plot:
|
if new_plot:
|
||||||
plt.figure()
|
plt.figure()
|
||||||
party_colors=np.array(range(len(party_index_mapping)))
|
|
||||||
|
|
||||||
if randomize_positions:
|
if randomize_positions:
|
||||||
xs_disp = parties[0].to_numpy() + np.random.rand(parties.shape[0]) - 0.5
|
xs_disp = parties[0].to_numpy() + np.random.rand(parties.shape[0]) - 0.5
|
||||||
@@ -194,12 +192,12 @@ def plot_parties(parties, randomize_positions=False, new_plot=True):
|
|||||||
xs_disp = parties[0].to_numpy()
|
xs_disp = parties[0].to_numpy()
|
||||||
ys_disp = parties[1].to_numpy()
|
ys_disp = parties[1].to_numpy()
|
||||||
|
|
||||||
plt.scatter(xs_disp , ys_disp, c=party_colors, cmap=cmap)
|
fig, ax = plt.subplots()
|
||||||
|
for i, party in enumerate(party_index_mapping):
|
||||||
|
print("Party", party, " x = ", xs_disp[i], "y = ", ys_disp[i])
|
||||||
|
plt.scatter(xs_disp[i], ys_disp[i], label=party)
|
||||||
|
plt.legend(title='Parties',bbox_to_anchor=(1.05, 1), loc='upper left')
|
||||||
|
|
||||||
# plotting labels
|
|
||||||
offset = 0.01
|
|
||||||
for x,y, party in zip(xs_disp, ys_disp, party_index_mapping):
|
|
||||||
plt.text(x + offset, y + offset, party)
|
|
||||||
def calc_party_distances(parties):
|
def calc_party_distances(parties):
|
||||||
distances = np.zeros((parties.shape[0], parties.shape[0]))
|
distances = np.zeros((parties.shape[0], parties.shape[0]))
|
||||||
for i, (_, left_party) in enumerate(parties.iterrows()):
|
for i, (_, left_party) in enumerate(parties.iterrows()):
|
||||||
|
|||||||
Reference in New Issue
Block a user