@@ -136,6 +136,7 @@ def plot_precincts(
136
136
voting_prefs_group1 ,
137
137
voting_prefs_group2 ,
138
138
group_names ,
139
+ candidate ,
139
140
precinct_labels = None ,
140
141
show_all_precincts = False ,
141
142
ax = None ,
@@ -151,6 +152,8 @@ def plot_precincts(
151
152
Same as voting_prefs_group2, except showing support among group 2
152
153
group_names: list of str
153
154
The demographic group names, for display in the legend
155
+ candidate: str
156
+ The candidate name
154
157
precinct_labels : list of str (optional)
155
158
The names for each precinct
156
159
show_all_precincts : bool, optional
@@ -207,13 +210,13 @@ def replace_ticks_with_precinct_labels(value, pos):
207
210
ax .set_yticks (np .arange (len (precinct_labels )))
208
211
ax .yaxis .set_major_formatter (mticker .FuncFormatter (replace_ticks_with_precinct_labels ))
209
212
ax .set_title ("Precinct level estimates of voting preferences" , fontsize = TITLESIZE )
210
- ax .set_xlabel ("Percent vote for candidate" , fontsize = FONTSIZE )
213
+ ax .set_xlabel (f "Percent vote for { candidate } " , fontsize = FONTSIZE )
211
214
ax .set_ylabel ("Precinct" , fontsize = FONTSIZE )
212
215
213
216
proxy_handles = [
214
217
mpatches .Patch (color = colors [i ], ec = "black" , label = group_names [i ]) for i in range (2 )
215
218
]
216
- ax .legend (handles = proxy_handles , loc = "upper center" )
219
+ ax .legend (handles = proxy_handles , prop = { "size" : 14 }, loc = "upper center" )
217
220
ax .set_ylim (- 1 , ax .get_ylim ()[1 ])
218
221
size_ticks (ax , "x" )
219
222
return ax
@@ -506,6 +509,7 @@ def plot_polarization_kde(
506
509
color = "steelblue" ,
507
510
linewidth = 0 ,
508
511
)
512
+ ax .set_ylabel ("Density" , fontsize = FONTSIZE )
509
513
if len (thresholds ) == 1 :
510
514
threshold_string = f"> { thresholds [0 ]:.2f} "
511
515
else :
@@ -521,6 +525,7 @@ def plot_polarization_kde(
521
525
thresholds [- 1 ] + 0.05 ,
522
526
0.5 ,
523
527
f"Prob (difference { threshold_string } ) = { probability :.1f} %" ,
528
+ fontsize = FONTSIZE ,
524
529
)
525
530
526
531
ax .set_title (f"Polarization KDE for { candidate_name } " , fontsize = TITLESIZE )
@@ -587,13 +592,14 @@ def plot_kdes(sampled_voting_prefs, group_names, candidate_names, plot_by="candi
587
592
else :
588
593
raise ValueError ("plot_by must be 'group' or 'candidate' (default: 'candidate')" )
589
594
595
+ middle_plot = int (np .floor (num_plots / 2 ))
590
596
for plot_idx in range (num_plots ):
591
597
if num_plots > 1 :
592
598
ax = axes [plot_idx ]
593
- ax .set_ylabel ("Density" , fontsize = FONTSIZE )
599
+ axes [ middle_plot ] .set_ylabel ("Probability Density" , fontsize = FONTSIZE )
594
600
else :
595
601
ax = axes
596
- ax .set_ylabel ("Probability Density" , fontsize = FONTSIZE )
602
+ axes .set_ylabel ("Probability Density" , fontsize = FONTSIZE )
597
603
ax .set_title (f"Support { support } " + titles [plot_idx ], fontsize = TITLESIZE )
598
604
ax .set_xlim ((0 , 1 ))
599
605
size_ticks (ax , "x" )
@@ -609,11 +615,12 @@ def plot_kdes(sampled_voting_prefs, group_names, candidate_names, plot_by="candi
609
615
color = colors [kde_idx ],
610
616
linewidth = 0 ,
611
617
)
618
+ ax .set_ylabel ("" )
612
619
613
620
if num_plots > 1 :
614
- axes [0 ].legend (bbox_to_anchor = (1 , 1 ), loc = "upper left" )
621
+ axes [middle_plot ].legend (bbox_to_anchor = (1 , 1 ), loc = "upper left" , prop = { "size" : 12 } )
615
622
else :
616
- ax .legend ()
623
+ ax .legend (prop = { "size" : 12 } )
617
624
return ax
618
625
619
626
0 commit comments