Closed gabeschoenbach closed 3 years ago
Awesome. Looks great!
And, yes, definitely, to your point about including more generalizations of the plotting functions for r x c -- we absolutely should do this! There are also places where there's currently redundancy in the plotting utilities that we can get rid of (e.g. there's a plot_kde function that is just for two groups, and plot_kdes that handles r x c). There are also non-plot-related opportunities for more refactoring with 2x2 and rxc, which I was going to hold off on until later, but hopefully not too much later.
Added a legend to the
ei.precinct_level_plot()
method, which callsplot_utils.plot_precincts()
.We first have to pass the list of demographic group names into
plot_precincts()
. Since there are really2 x num_precincts
matplotlibArtists
in the figure, I opted to create proxy handles for the legend. In order to ensure the legend and the KDE's draw the same colors, I put acolors
list intoplot_precincts()
function body to which both theplot_single_ridgeplots()
helper and the legend can point. Lastly, there needs to be space for the legend itself! Some experimentation showed me that creatinglegend_space = 5
extra lines at the top were enough to comfortably fit the legend box, and this seems to look fine when tested on 10, 20, and 42 precincts.Miscellaneous thoughts:
2x2
EI, but I don't think it would be crazy hard to generalize it toRxC
. I see that for the most part, the plotting/summary functions are separated between2x2
andRxC
. I imagine that there is certainly more important functionality to implement first, but do we ever want to think about generalizing the functions inplot_utils
toRxC
?num_precincts
increases, so does a the vertical buffer on the top and bottom of theplot_precincts()
figure. This isn't a huge problem withnum_precincts < 50
, but I wonder how it would look with many more precincts. Since I doubt many people will want to visually inspect hundreds of precincts with this function, this might not be an issue, but wanted to flag!