gerrytools 2.0.2__tar.gz → 2.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. {gerrytools-2.0.2 → gerrytools-2.0.3}/PKG-INFO +1 -1
  2. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/run_container.py +1 -1
  3. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/_axis_api.py +37 -5
  4. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/histogram.py +89 -35
  5. {gerrytools-2.0.2 → gerrytools-2.0.3}/pyproject.toml +1 -1
  6. {gerrytools-2.0.2 → gerrytools-2.0.3}/LICENSE +0 -0
  7. {gerrytools-2.0.2 → gerrytools-2.0.3}/README.md +0 -0
  8. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/__init__.py +0 -0
  9. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/_election_math.py +0 -0
  10. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/_geodataframe.py +0 -0
  11. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/_geometry.py +0 -0
  12. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/_ipython.py +0 -0
  13. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/_partisan_math.py +0 -0
  14. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/_scoring_engine.pyi +0 -0
  15. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/ben/__init__.py +0 -0
  16. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/ben/_graph_prep.py +0 -0
  17. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/ben/recorded_chain.py +0 -0
  18. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/__init__.py +0 -0
  19. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/_latex_table.py +0 -0
  20. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/_sources.py +0 -0
  21. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/_value.py +0 -0
  22. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/core.py +0 -0
  23. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/districtr.py +0 -0
  24. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/latex.py +0 -0
  25. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/seaborn.py +0 -0
  26. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/colors/utils.py +0 -0
  27. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/__init__.py +0 -0
  28. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/_geometry_etags.py +0 -0
  29. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/geometries.py +0 -0
  30. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/uscensus/__init__.py +0 -0
  31. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/uscensus/_api.py +0 -0
  32. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/uscensus/acs.py +0 -0
  33. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/uscensus/block_cvap.py +0 -0
  34. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/uscensus/census.py +0 -0
  35. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/uscensus/census_tables.py +0 -0
  36. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/data/uscensus/ptable_column_aliases.py +0 -0
  37. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/__init__.py +0 -0
  38. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/_colors.py +0 -0
  39. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/_render.py +0 -0
  40. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/_table_base.py +0 -0
  41. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/_table_layout.py +0 -0
  42. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/_table_options.py +0 -0
  43. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/_table_preamble.py +0 -0
  44. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/_text.py +0 -0
  45. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/_tikz_plot_base.py +0 -0
  46. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/commands.py +0 -0
  47. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/document.py +0 -0
  48. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/formatters.py +0 -0
  49. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/paintball.py +0 -0
  50. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/seatsvotes.py +0 -0
  51. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/table.py +0 -0
  52. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/latex/tikz_table.py +0 -0
  53. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/logging.py +0 -0
  54. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/__init__.py +0 -0
  55. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/constraints.py +0 -0
  56. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/objectives.py +0 -0
  57. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/run_config.py +0 -0
  58. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/runners/__init__.py +0 -0
  59. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/runners/forest.py +0 -0
  60. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/runners/recom.py +0 -0
  61. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/mgrp/runners/smc.py +0 -0
  62. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plan_comparison/__init__.py +0 -0
  63. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plan_comparison/overlap.py +0 -0
  64. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plan_comparison/relabel.py +0 -0
  65. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/__init__.py +0 -0
  66. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/_artist_registry.py +0 -0
  67. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/_axes_backed.py +0 -0
  68. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/_axes_state.py +0 -0
  69. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/_figure_io.py +0 -0
  70. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/_legend_mixin.py +0 -0
  71. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/_legend_utils.py +0 -0
  72. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/_rng.py +0 -0
  73. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/__init__.py +0 -0
  74. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/_annotation_api.py +0 -0
  75. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/_annotations.py +0 -0
  76. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/_arrow_renderer.py +0 -0
  77. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/_categorical_distribution_base.py +0 -0
  78. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/_gerryplot_dataclasses.py +0 -0
  79. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/_unit_square_base.py +0 -0
  80. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/barplot.py +0 -0
  81. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/boxplot.py +0 -0
  82. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/gerryplot.py +0 -0
  83. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/options.py +0 -0
  84. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/paintball.py +0 -0
  85. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/scatterplot.py +0 -0
  86. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/sealevel.py +0 -0
  87. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/seatsvotes.py +0 -0
  88. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/data/violin.py +0 -0
  89. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/__init__.py +0 -0
  90. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/_dot_sampling.py +0 -0
  91. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/_labels.py +0 -0
  92. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/_layers/__init__.py +0 -0
  93. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/_layers/_base.py +0 -0
  94. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/_layers/_categorical.py +0 -0
  95. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/_layers/_continuous.py +0 -0
  96. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/_layers/_marker.py +0 -0
  97. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/dotdensity.py +0 -0
  98. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/geoplot.py +0 -0
  99. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/geometry/geoplotbase.py +0 -0
  100. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/mpl/__init__.py +0 -0
  101. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/mpl/axis_title_style.py +0 -0
  102. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/mpl/geoplot_options.py +0 -0
  103. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/mpl/label_text_options.py +0 -0
  104. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/mpl/legend_options.py +0 -0
  105. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/mpl/marker_options.py +0 -0
  106. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/mpl/tick_style.py +0 -0
  107. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/other/__init__.py +0 -0
  108. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/other/subway.py +0 -0
  109. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/plan/__init__.py +0 -0
  110. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/plan/drawgraph.py +0 -0
  111. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/plotting/utils.py +0 -0
  112. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/py.typed +0 -0
  113. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/__init__.py +0 -0
  114. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/_manifest.py +0 -0
  115. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/_types.py +0 -0
  116. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/evaluator.py +0 -0
  117. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/formulas.py +0 -0
  118. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/metrics/__init__.py +0 -0
  119. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/metrics/_base.py +0 -0
  120. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/metrics/_geometry.py +0 -0
  121. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/result.py +0 -0
  122. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/single_plan/__init__.py +0 -0
  123. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/single_plan/_base.py +0 -0
  124. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/scoring/single_plan/_geometry.py +0 -0
  125. {gerrytools-2.0.2 → gerrytools-2.0.3}/gerrytools/typing.py +0 -0
  126. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/Cargo.lock +0 -0
  127. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/Cargo.toml +0 -0
  128. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/README.md +0 -0
  129. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/adjacency.rs +0 -0
  130. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/error.rs +0 -0
  131. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/geometry/mod.rs +0 -0
  132. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/geometry/precise_area.rs +0 -0
  133. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/geometry/unit_hulls.rs +0 -0
  134. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/lib.rs +0 -0
  135. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/area_perimeter.rs +0 -0
  136. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/convex_hull_ratio.rs +0 -0
  137. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/cut_edges.rs +0 -0
  138. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/formulas.rs +0 -0
  139. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/hull_metric.rs +0 -0
  140. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/mod.rs +0 -0
  141. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/polsby_popper.rs +0 -0
  142. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/population_polygon.rs +0 -0
  143. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/region.rs +0 -0
  144. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/region_parts.rs +0 -0
  145. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/region_tally.rs +0 -0
  146. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/reock.rs +0 -0
  147. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/schwartzberg.rs +0 -0
  148. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/state_clipped_convex_hull_ratio.rs +0 -0
  149. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/metrics/tally.rs +0 -0
  150. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/python.rs +0 -0
  151. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/scoring/delta.rs +0 -0
  152. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/scoring/district.rs +0 -0
  153. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/scoring/input.rs +0 -0
  154. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/scoring/mod.rs +0 -0
  155. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/scoring/output.rs +0 -0
  156. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/scoring/result.rs +0 -0
  157. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/scoring/stream.rs +0 -0
  158. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/scoring/uniqueness.rs +0 -0
  159. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/convex_hull_ratio.rs +0 -0
  160. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/cut_edges.rs +0 -0
  161. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/district.rs +0 -0
  162. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/formulas.rs +0 -0
  163. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/geometry.rs +0 -0
  164. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/input.rs +0 -0
  165. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/output.rs +0 -0
  166. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/polsby_popper.rs +0 -0
  167. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/population_polygon.rs +0 -0
  168. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/region.rs +0 -0
  169. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/region_tally.rs +0 -0
  170. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/reock.rs +0 -0
  171. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/schwartzberg.rs +0 -0
  172. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/state_clipped_convex_hull_ratio.rs +0 -0
  173. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/stream.rs +0 -0
  174. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/support.rs +0 -0
  175. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/tally.rs +0 -0
  176. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/twodelta.rs +0 -0
  177. {gerrytools-2.0.2 → gerrytools-2.0.3}/rust/src/tests/unit_hulls.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gerrytools
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Python :: 3.11
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -22,7 +22,7 @@ from gerrychain import Graph, Partition
22
22
 
23
23
  logger = logging.getLogger(__name__)
24
24
 
25
- DEFAULT_DOCKER_IMAGE = "mgggdev/replicate:v2.0.2@sha256:fe03dd8c70e72e15d50410317892c32a6b04e1d254d0a4af6f16b4a10d14768f"
25
+ DEFAULT_DOCKER_IMAGE = "mgggdev/replicate:v2.0.3@sha256:fe03dd8c70e72e15d50410317892c32a6b04e1d254d0a4af6f16b4a10d14768f"
26
26
 
27
27
  BINARY_WRITERS = ("pcompress", "ben", "bendl")
28
28
  """Writers whose output cannot be decoded from a console stream."""
@@ -16,6 +16,7 @@ from typing import Generic, Literal, Sequence, TypeVar
16
16
  import matplotlib
17
17
  from matplotlib.axes import Axes
18
18
  from matplotlib.text import Text
19
+ from matplotlib.ticker import Formatter
19
20
 
20
21
  from gerrytools.colors import resolve_rgba
21
22
  from gerrytools.plotting._axes_backed import deferred_axis_update
@@ -201,6 +202,21 @@ class _TitleText(_ManagedText[TitleStyle]):
201
202
  return _title_snapshot(ax)
202
203
 
203
204
 
205
+ class _PositionLabelFormatter(Formatter):
206
+ """Labels tied to fixed locations, retaining the formatter they displaced on this axis."""
207
+
208
+ def __init__(
209
+ self, owner: _AxisState, previous: Formatter, locations: list[float], labels: list[str]
210
+ ) -> None:
211
+ super().__init__()
212
+ self.owner = owner
213
+ self.previous = previous
214
+ self._labels = dict(zip(locations, labels, strict=True))
215
+
216
+ def __call__(self, x: float, pos: int | None = None) -> str:
217
+ return self._labels.get(x, "")
218
+
219
+
204
220
  class _AxisState:
205
221
  """One axis's managed configuration plus x/y-dispatching matplotlib accessors."""
206
222
 
@@ -227,7 +243,20 @@ class _AxisState:
227
243
  (ax.set_xticks if self.axis == "x" else ax.set_yticks)(locations)
228
244
 
229
245
  def set_ticklabels(self, ax: Axes, labels: list[str]) -> None:
230
- (ax.set_xticklabels if self.axis == "x" else ax.set_yticklabels)(labels)
246
+ axis = ax.xaxis if self.axis == "x" else ax.yaxis
247
+ previous = axis.get_major_formatter()
248
+ if isinstance(previous, _PositionLabelFormatter) and previous.owner is self:
249
+ previous = previous.previous
250
+
251
+ axis.set_major_formatter(
252
+ _PositionLabelFormatter(self, previous, self.get_ticks(ax), labels)
253
+ )
254
+
255
+ def restore_tick_formatter(self, ax: Axes) -> None:
256
+ axis = ax.xaxis if self.axis == "x" else ax.yaxis
257
+ current = axis.get_major_formatter()
258
+ if isinstance(current, _PositionLabelFormatter) and current.owner is self:
259
+ axis.set_major_formatter(current.previous)
231
260
 
232
261
  def get_ticks(self, ax: Axes) -> list[float]:
233
262
  ticks = ax.get_xticks() if self.axis == "x" else ax.get_yticks()
@@ -593,10 +622,13 @@ class _AxisApiMixin(_TitleApiMixin):
593
622
  if tick_locations is None:
594
623
  # Matplotlib will compute labels from the locator at draw time; nothing to apply.
595
624
  return
596
- if axis.axis == "x":
597
- default_labels = self._default_x_tick_labels(tick_locations)
598
- if default_labels is not None:
599
- axis.set_ticklabels(self._ax, list(default_labels))
625
+ default_labels = (
626
+ self._default_x_tick_labels(tick_locations) if axis.axis == "x" else None
627
+ )
628
+ if default_labels is None:
629
+ axis.restore_tick_formatter(self._ax)
630
+ else:
631
+ axis.set_ticklabels(self._ax, list(default_labels))
600
632
  return
601
633
  if tick_locations is None:
602
634
  tick_locations = axis.get_ticks(self._ax)
@@ -176,6 +176,7 @@ class Histogram(GerryPlotBase):
176
176
  self._show_warnings = True
177
177
  self._bins: BinsType | None = None
178
178
  self._bin_alignment = "edge"
179
+ self._bin_center_ticks: list[float] | None = None
179
180
  self._as_density_plot = False
180
181
  self._binwidth: float | None = None
181
182
 
@@ -204,16 +205,46 @@ class Histogram(GerryPlotBase):
204
205
 
205
206
  @deferred_axis_update
206
207
  def center_bars(self) -> None:
207
- """Center histogram data on bin edges."""
208
+ """Center the histogram bars according to the bin specification.
209
+
210
+ With :meth:`set_bin_widths`, the first bin is centered on the minimum across all datasets.
211
+ Successive centers are one bin width apart. Each bin includes its left edge and excludes
212
+ its right edge. For example, with width 1, the values ``[1, 1.5, 2]`` give counts of
213
+ 1 at center 1 and 2 at center 2.
214
+
215
+ With automatic bins or :meth:`set_bins`, the bars shift half a bin width to the left
216
+ for display. The original edges still determine the counts. The bins must have uniform
217
+ widths for centering or the plot raises ``ValueError`` when drawn.
218
+ """
208
219
  self._bin_alignment = "center"
209
220
 
221
+ @deferred_axis_update
222
+ def set_xticks_at_bin_centers(self) -> None:
223
+ """Place one x-axis tick at the center of each displayed bin.
224
+
225
+ Tick locations follow the bins as datasets or bin settings change. Grouped bars share
226
+ one tick per bin. This replaces labels tied to previous locations with the axis's own
227
+ formatting. Labels explicitly hidden with ``set_xticks(labels=[])`` stay hidden.
228
+ To label the new positions yourself, call :meth:`set_xticks` afterward with one label
229
+ per bin.
230
+ """
231
+ self._bin_center_ticks = []
232
+ if self._xaxis.tick_labels != [] or self._xaxis.tick_locations == []:
233
+ self._xaxis.tick_labels = None
234
+ self._xaxis.tick_locations = None
235
+ self._axes_state.reclaim_without_value(self._xaxis.unit_ticks)
236
+
237
+ def _default_x_tick_locations(self) -> list[float] | None:
238
+ return self._bin_center_ticks
239
+
210
240
  @deferred_axis_update
211
241
  def set_bins(self, bins: BinsType | None) -> None:
212
242
  """Set the bins for the histogram.
213
243
 
214
244
  Bins can be specified either as an array of bin edges, an integer number of bins,
215
- or a string (e.g., 'auto') to use numpy's histogram binning strategies. The binning
216
- strategies possible strategies are as follows:
245
+ or a string (e.g., 'auto') to use NumPy's histogram binning strategies. Adjacent edges
246
+ define one bin. Each bin includes its left edge, and the final bin also includes its
247
+ right edge. NumPy supports the following strategies.
217
248
 
218
249
  - ‘auto’: Minimum bin width between the ‘sturges’ and ‘fd’ estimators. Provides good
219
250
  all-around performance.
@@ -252,8 +283,11 @@ class Histogram(GerryPlotBase):
252
283
  def set_bin_widths(self, binwidth: float | None) -> None:
253
284
  """Set histogram bins by specifying a fixed bin width.
254
285
 
255
- The histogram bins will be computed automatically based on the minimum and maximum
256
- values across all histogram sets added to the figure.
286
+ The bins start at the minimum across all datasets. Calling :meth:`center_bars` places
287
+ the first bin's center at that minimum instead. In either alignment, a bin includes
288
+ its left edge and excludes its right edge. The final edge is above the maximum so every
289
+ observation falls in a bin. If the width is too small to distinguish adjacent edges at the
290
+ scale of the data, the plot raises ``ValueError`` when drawn.
257
291
 
258
292
  Args:
259
293
  binwidth (float | None): Desired width of each histogram bin. If None, the
@@ -531,43 +565,52 @@ class Histogram(GerryPlotBase):
531
565
 
532
566
  def _compute_bins(self) -> NDArray[np.float64]:
533
567
  """Compute histogram bins based on current settings and data."""
534
- bins = self._bins
535
- if bins is None and self._binwidth is None:
536
- bins = "auto"
537
-
538
568
  all_values = np.concatenate(
539
569
  [hdata.values for hdata in chain(*self._hist_data_dict.values())]
540
570
  )
541
- if bins is None and self._binwidth is not None:
542
- minscore, maxscore = np.min(all_values), np.max(all_values)
543
- binwidth = self._binwidth
544
- n_bins = max(1, int(np.ceil((maxscore - minscore) / binwidth)))
545
- bins = minscore + np.arange(n_bins + 1) * binwidth
571
+ bin_width = self._binwidth
572
+ if bin_width is None:
573
+ bins = "auto" if self._bins is None else self._bins
574
+ return np.histogram_bin_edges(all_values, bins=bins)
575
+
576
+ minimum, maximum = np.min(all_values), np.max(all_values)
577
+ first_edge = minimum - bin_width / 2 if self._bin_alignment == "center" else minimum
578
+ bin_count = max(1, int(np.ceil((maximum - first_edge) / bin_width)))
579
+ edges = first_edge + np.arange(bin_count + 1) * bin_width
580
+
581
+ if edges[-1] <= maximum:
582
+ edges = np.append(edges, first_edge + (bin_count + 1) * bin_width)
583
+ else:
584
+ # The span and the edges round separately. Keep the first edge above the maximum.
585
+ edges = edges[: np.searchsorted(edges, maximum, side="right") + 1]
546
586
 
547
587
  if (
548
- bins is None
549
- ): # pragma: no cover - preceding logic always assigns bins; this is an unreachable guard
550
- raise RuntimeError("Failed to compute histogram bins.") # pragma: no cover
588
+ not np.isfinite(edges).all()
589
+ or not (edges[1:] > edges[:-1]).all()
590
+ or edges[-1] <= maximum
591
+ ):
592
+ raise ValueError("The bin width must produce distinct finite edges spanning the data.")
551
593
 
552
- bins = np.histogram_bin_edges(all_values, bins=bins)
553
- return bins
594
+ return edges
554
595
 
555
596
  def _display_edges(self, bin_edges: NDArray[np.float64]) -> NDArray[np.float64]:
556
597
  """Bin edges shifted to where bars are drawn.
557
598
 
558
- Centering data on bin edges is a half-binwidth left shift of the drawn edges; binning
559
- itself always uses the raw edges. Everything (bars, outlines, grouped offsets, points)
560
- derives its x-positions from these display edges, so the alignment mode lives here only.
599
+ Fixed-width bins already incorporate their alignment when their edges are computed.
600
+ For other bin specifications, centering shifts the drawing by half a bin width.
561
601
  """
562
- if self._bin_alignment == "center":
602
+ if self._bin_alignment == "center" and self._binwidth is None:
563
603
  return bin_edges - 0.5 * (bin_edges[1] - bin_edges[0])
564
604
  return bin_edges
565
605
 
566
- def _draw_histograms(self, bin_edges: NDArray[np.float64]) -> NDArray[np.float64]:
606
+ def _draw_histograms(
607
+ self, bin_edges: NDArray[np.float64], display_edges: NDArray[np.float64]
608
+ ) -> NDArray[np.float64]:
567
609
  """Draw the histograms on the plot.
568
610
 
569
611
  Args:
570
612
  bin_edges (NDArray[np.float64]): Shared bin edges computed once per build.
613
+ display_edges (NDArray[np.float64]): X-coordinates of the drawn bin edges.
571
614
 
572
615
  Returns:
573
616
  NDArray[np.float64]: Per-bin maximum bar-top heights across every series (stacked tops
@@ -580,7 +623,6 @@ class Histogram(GerryPlotBase):
580
623
  raise ValueError(
581
624
  "Cannot center histogram data on bin edges when bin widths are not uniform."
582
625
  )
583
- display_edges = self._display_edges(bin_edges)
584
626
 
585
627
  for histtype, histlist in self._hist_data_dict.items():
586
628
  hist_bottoms = np.zeros(len(bin_edges) - 1)
@@ -675,7 +717,11 @@ class Histogram(GerryPlotBase):
675
717
  return max_heights
676
718
 
677
719
  def _draw_points(
678
- self, bin_edges: NDArray[np.float64], max_heights: NDArray[np.float64]
720
+ self,
721
+ bin_edges: NDArray[np.float64],
722
+ display_edges: NDArray[np.float64],
723
+ bin_centers: NDArray[np.float64],
724
+ max_heights: NDArray[np.float64],
679
725
  ) -> None:
680
726
  """Draw the points on the histogram plot.
681
727
 
@@ -684,6 +730,8 @@ class Histogram(GerryPlotBase):
684
730
 
685
731
  Args:
686
732
  bin_edges (NDArray[np.float64]): Shared bin edges computed once per build.
733
+ display_edges (NDArray[np.float64]): Edges used to locate a marker at its actual x-value.
734
+ bin_centers (NDArray[np.float64]): Display coordinates for markers snapped to a bin.
687
735
  max_heights (NDArray[np.float64]): Per-bin maximum bar-top heights from
688
736
  ``_draw_histograms``. Mutated in place as points stack above bars.
689
737
  """
@@ -694,9 +742,6 @@ class Histogram(GerryPlotBase):
694
742
  _recompute_data_limits(self._ax)
695
743
  self._ax.autoscale_view()
696
744
 
697
- display_edges = self._display_edges(bin_edges)
698
- bin_centers = (display_edges[:-1] + display_edges[1:]) / 2.0
699
-
700
745
  def clearance_data_units(clearance_pt: float, y_top: float) -> float:
701
746
  """Convert a point-space clearance to y-data units at ``y_top``."""
702
747
  px = clearance_pt * self._ax.figure.dpi / 72.0
@@ -715,11 +760,14 @@ class Histogram(GerryPlotBase):
715
760
  x_positions = np.array(pointlist.values)
716
761
  y_positions = []
717
762
  visited_indexes = set()
763
+
718
764
  placement_edges = bin_edges if pointlist.centered else display_edges
719
- for i, val in enumerate(pointlist.values):
720
- bin_idx = int(np.searchsorted(placement_edges, val, side="right")) - 1
721
- if val == placement_edges[-1]:
722
- bin_idx -= 1
765
+ bin_indices = np.searchsorted(placement_edges, pointlist.values, side="right") - 1
766
+ if self._binwidth is None: # NumPy includes the last edge for these bins.
767
+ bin_indices[pointlist.values == placement_edges[-1]] = len(max_heights) - 1
768
+
769
+ for i, index in enumerate(bin_indices):
770
+ bin_idx = int(index)
723
771
  in_range = 0 <= bin_idx < len(max_heights)
724
772
  stack_idx = bin_idx if in_range else (-1 if bin_idx < 0 else len(max_heights))
725
773
  height = (
@@ -768,9 +816,15 @@ class Histogram(GerryPlotBase):
768
816
  """Build the histogram plot."""
769
817
  if sum(len(lst) for lst in self._hist_data_dict.values()) == 0:
770
818
  raise ValueError("No histogram sets added yet.")
819
+
771
820
  bin_edges = self._compute_bins()
772
- max_heights = self._draw_histograms(bin_edges)
773
- self._draw_points(bin_edges, max_heights)
821
+ display_edges = self._display_edges(bin_edges)
822
+ bin_centers = display_edges[:-1] + np.diff(display_edges) / 2
823
+ if self._bin_center_ticks is not None:
824
+ self._bin_center_ticks = bin_centers.tolist()
825
+
826
+ max_heights = self._draw_histograms(bin_edges, display_edges)
827
+ self._draw_points(bin_edges, display_edges, bin_centers, max_heights)
774
828
 
775
829
  def _dataset_legend_handles(self) -> list[LegendHandle]:
776
830
  """Get legend handles for the histogram sets."""
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "gerrytools"
7
- version = "2.0.2"
7
+ version = "2.0.3"
8
8
  description = "Tools for processing and visualizing districting plans."
9
9
  readme = "README.md"
10
10
  authors = [
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes