Sea-level plots¶
SeaLevelPlot connects one plan’s values across an ordered set of categories. Repeating that
operation for many plans creates the characteristic sea of lines.
from gerrytools.plotting import SeaLevelPlot
starting_plan = {
"President 2016": 7 / 14,
"Governor 2018": 6 / 14,
"President 2020": 7 / 14,
"U.S. Senate 2020": 8 / 14,
}
plot = SeaLevelPlot()
plot.add_dataset(starting_plan, linecolor="alizarin")
plot.show()
A mapping keeps category labels and order with the values. Lists, Series objects, and one DataFrame row are also accepted.
Frequently, it is useful to change the scale of the y-axis to use fractional values. There is also a convenience function for this.
plot = SeaLevelPlot()
plot.add_dataset(starting_plan, linecolor="alizarin")
plot.format_ylabels_as_fractions(denominator=14)
plot.set_ylim(3 / 14, 10 / 14)
plot.show()
It is also common to try and plot multiple plans on the same set of axis. Since seat counts are discrete, this can cause a collision leaving one or more of the lines difficult to see. Visibility can be improved by adding some jitter to the plot.
plan_2 = {
"President 2016": 5 / 14,
"Governor 2018": 6 / 14,
"President 2020": 7 / 14,
"U.S. Senate 2020": 5 / 14,
}
plot = SeaLevelPlot(jitter_rng_seed=42)
plot.add_dataset(starting_plan, linecolor="alizarin")
plot.add_dataset(plan_2, linecolor="default_grey")
plot.format_ylabels_as_fractions(denominator=14)
plot.set_vertical_jitter(0.01)
plot.set_horizontal_jitter(0.01)
plot.set_ylim(3 / 14, 10 / 14)
plot.show()
Shared axes, labels, legends, and output controls are covered in shared statistical controls.