mgplot 0.2.24__tar.gz → 0.2.26__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 (59) hide show
  1. {mgplot-0.2.24 → mgplot-0.2.26}/CHANGELOG.md +61 -0
  2. {mgplot-0.2.24 → mgplot-0.2.26}/PKG-INFO +91 -3
  3. {mgplot-0.2.24 → mgplot-0.2.26}/README.md +90 -2
  4. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/bar_plot.html +676 -518
  5. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/fill_between_plot.html +213 -186
  6. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/finalise_plot.html +351 -337
  7. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/growth_plot.html +446 -418
  8. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/line_plot.html +372 -346
  9. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/postcovid_plot.html +1 -0
  10. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/run_plot.html +17 -6
  11. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/summary_plot.html +356 -348
  12. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot.html +939 -747
  13. mgplot-0.2.26/docs/search.js +46 -0
  14. {mgplot-0.2.24 → mgplot-0.2.26}/pyproject.toml +1 -1
  15. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/axis_utils.py +64 -7
  16. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/bar_plot.py +96 -33
  17. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/fill_between_plot.py +8 -1
  18. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/finalise_plot.py +5 -2
  19. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/growth_plot.py +8 -1
  20. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/keyword_checking.py +4 -1
  21. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/line_plot.py +8 -2
  22. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/run_plot.py +6 -1
  23. mgplot-0.2.26/test/test_bar_horizontal.py +126 -0
  24. mgplot-0.2.26/test/test_tick_relabel.py +90 -0
  25. {mgplot-0.2.24 → mgplot-0.2.26}/uv.lock +22 -22
  26. mgplot-0.2.24/docs/search.js +0 -46
  27. {mgplot-0.2.24 → mgplot-0.2.26}/.claude/settings.local.json +0 -0
  28. {mgplot-0.2.24 → mgplot-0.2.26}/.gitignore +0 -0
  29. {mgplot-0.2.24 → mgplot-0.2.26}/.pylintrc +0 -0
  30. {mgplot-0.2.24 → mgplot-0.2.26}/.python-version +0 -0
  31. {mgplot-0.2.24 → mgplot-0.2.26}/LICENSE +0 -0
  32. {mgplot-0.2.24 → mgplot-0.2.26}/build-all.sh +0 -0
  33. {mgplot-0.2.24 → mgplot-0.2.26}/build-docs.sh +0 -0
  34. {mgplot-0.2.24 → mgplot-0.2.26}/docs/index.html +0 -0
  35. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/revision_plot.html +0 -0
  36. {mgplot-0.2.24 → mgplot-0.2.26}/docs/mgplot/seastrend_plot.html +0 -0
  37. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/__init__.py +0 -0
  38. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/colors.py +0 -0
  39. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/finalisers.py +0 -0
  40. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/lint-all.sh +0 -0
  41. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/multi_plot.py +0 -0
  42. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/postcovid_plot.py +0 -0
  43. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/py.typed +0 -0
  44. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/revision_plot.py +0 -0
  45. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/seastrend_plot.py +0 -0
  46. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/settings.py +0 -0
  47. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/summary_plot.py +0 -0
  48. {mgplot-0.2.24 → mgplot-0.2.26}/src/mgplot/utilities.py +0 -0
  49. {mgplot-0.2.24 → mgplot-0.2.26}/test/test-executed.ipynb +0 -0
  50. {mgplot-0.2.24 → mgplot-0.2.26}/test/test.ipynb +0 -0
  51. {mgplot-0.2.24 → mgplot-0.2.26}/test/test_bar_string_index.py +0 -0
  52. {mgplot-0.2.24 → mgplot-0.2.26}/test/test_chart_subdir.py +0 -0
  53. {mgplot-0.2.24 → mgplot-0.2.26}/test/test_multi_series_ticks.py +0 -0
  54. {mgplot-0.2.24 → mgplot-0.2.26}/test/test_splat_sequences.py +0 -0
  55. {mgplot-0.2.24 → mgplot-0.2.26}/test/test_zorder.py +0 -0
  56. {mgplot-0.2.24 → mgplot-0.2.26}/test/zz-test-data/ocr_rba.csv +0 -0
  57. {mgplot-0.2.24 → mgplot-0.2.26}/test/zz-test-data/revisions.csv +0 -0
  58. {mgplot-0.2.24 → mgplot-0.2.26}/test/zz-test-data/summary.csv +0 -0
  59. {mgplot-0.2.24 → mgplot-0.2.26}/uv-upgrade.sh +0 -0
@@ -1,3 +1,64 @@
1
+ Version 0.2.26 - released 5-Jun-2026 (Canberra, Australia)
2
+
3
+ * enhancement
4
+ - added horizontal=True to bar_plot() (and bar_plot_finalise()):
5
+ plots grouped or stacked horizontal bars with category labels on
6
+ the y-axis and values along the x-axis. Designed for categorical
7
+ (string-indexed) data - ranked states, industries, expenditure
8
+ classes and the like. Bar annotations are placed at the bar ends
9
+ (or within bars), vertically centred. Sign-aware stacking
10
+ (negatives leftward, positives rightward) works as for vertical
11
+ stacked bars. horizontal=True with a PeriodIndex warns and falls
12
+ back to a vertical plot - period tick labelling is x-axis only
13
+ - bar_plot() with a single series now accepts one colour per bar:
14
+ if color is a sequence whose length matches the data, each bar is
15
+ painted individually (e.g. state colours on a ranked horizontal
16
+ bar chart). The in-bar annotation stroke effect picks the matching
17
+ per-bar colour. Multi-series colour semantics are unchanged
18
+ - added test/test_bar_horizontal.py covering string-index labels,
19
+ annotations, grouped/stacked, negative stacking, the PeriodIndex
20
+ fallback, per-bar colours, and label survival through
21
+ finalise_plot()
22
+
23
+ ---
24
+
25
+ Version 0.2.25 - released 5-Jun-2026 (Canberra, Australia)
26
+
27
+ * enhancement
28
+ - added tick_relabel keyword argument to line_plot(), bar_plot(),
29
+ growth_plot(), fill_between_plot() and run_plot() (and their
30
+ *_finalise variants): a callable applied to each generated x-axis
31
+ tick label after the contextual labellers have run (e.g. shorten
32
+ 4-digit years to 2 digits)
33
+ - tick-label options (max_ticks, label rotation, tick_relabel) are
34
+ now stashed on the Axes by set_labels() and honoured when
35
+ finalise_plot() refreshes the labels before saving. Previously the
36
+ refresh regenerated labels with hard-coded defaults (max_ticks=10,
37
+ rotation=0), silently discarding per-plot settings
38
+ - added register_label_options() / get_label_options() to
39
+ axis_utils.py to support the above
40
+ - keyword checking now validates Callable annotations (checks
41
+ callability; previously a parameterized Callable would error)
42
+ - added test/test_tick_relabel.py covering tick_relabel, max_ticks
43
+ and label_rotation persistence through finalise_plot(), and
44
+ correct-figure close behaviour
45
+ - documented tick labelling and the multi-panel axes_only pattern
46
+ in README.md (new "Axis Tick Labels" and "Multi-Panel Figures"
47
+ sections)
48
+
49
+ * bug fix
50
+ - bar_plot() applied label_rotation via plt.xticks(), which targets
51
+ pyplot's current axes rather than the axes being plotted (wrong
52
+ panel in multi-axes figures), and the rotation was then lost when
53
+ finalise_plot() refreshed PeriodIndex labels. Rotation now goes
54
+ via the stashed label options (PeriodIndex) or set_xticklabels()
55
+ (string index)
56
+ - finalise_plot() closed pyplot's current figure (plt.close()) rather
57
+ than the figure belonging to the axes being finalised; it now closes
58
+ the correct figure (walking up from a SubFigure if necessary)
59
+
60
+ ---
61
+
1
62
  Version 0.2.24 - released 4-Jun-2026 (Canberra, Australia)
2
63
 
3
64
  * enhancement
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mgplot
3
- Version: 0.2.24
3
+ Version: 0.2.26
4
4
  Summary: mgplot is a time-series/PeriodIndex frontend for matplotlib
5
5
  Project-URL: Repository, https://github.com/bpalmer4/mgplot
6
6
  Project-URL: Homepage, https://github.com/bpalmer4/mgplot
@@ -68,8 +68,9 @@ All plot functions take a pandas Series or DataFrame with a PeriodIndex
68
68
  as the first argument and return a matplotlib Axes object. Keyword
69
69
  arguments control styling and behavior:
70
70
 
71
- - `bar_plot()` -- vertical bar plot (grouped or stacked) with intelligent
72
- PeriodIndex labeling
71
+ - `bar_plot()` -- bar plot (grouped or stacked) with intelligent
72
+ PeriodIndex labeling; `horizontal=True` plots categorical data as
73
+ horizontal bars (categories on the y-axis, values along the x-axis)
73
74
  - `fill_between_plot()` -- shaded region between two bounds (requires
74
75
  2-column DataFrame)
75
76
  - `growth_plot()` -- plots annual and periodic growth rates (requires
@@ -85,6 +86,25 @@ arguments control styling and behavior:
85
86
  - `summary_plot()` -- latest data point against historical range with
86
87
  z-score visualization
87
88
 
89
+ For ranked-category charts (states, industries, expenditure classes),
90
+ use `horizontal=True` with a string-indexed Series or DataFrame:
91
+
92
+ ```python
93
+ vacancies = vacancies.sort_values() # smallest at the bottom
94
+ mg.bar_plot_finalise(
95
+ vacancies,
96
+ horizontal=True,
97
+ annotate=True, # value labels at the bar ends
98
+ above=True,
99
+ x0=True, # zero line on the value axis
100
+ title="Job vacancies by industry",
101
+ xlabel="'000",
102
+ )
103
+ ```
104
+
105
+ `horizontal=True` is for categorical data: with a PeriodIndex it warns
106
+ and falls back to a vertical plot.
107
+
88
108
  Finalising Plots
89
109
  ----------------
90
110
  Once a plot is generated, finalise it with titles, labels, and save to file:
@@ -94,6 +114,74 @@ ax = mg.line_plot(data)
94
114
  mg.finalise_plot(ax, title="My Chart", ylabel="Units", tag="my_chart")
95
115
  ```
96
116
 
117
+ Axis Tick Labels
118
+ ----------------
119
+ For PeriodIndex data, x-axis tick labels are generated contextually:
120
+ the tick density is chosen to fit within `max_ticks`, and labels show
121
+ the period with years marked at transitions (e.g. a monthly axis shows
122
+ `Feb Mar ... 2024 ... Feb`, a quarterly axis shows `Q2 Q3 2025 Q2`).
123
+
124
+ Three keyword arguments control the labels on the period-indexed plot
125
+ functions (`line_plot`, `bar_plot`, `growth_plot`, `fill_between_plot`,
126
+ `run_plot`, and their `*_finalise` variants):
127
+
128
+ - `max_ticks` -- the maximum number of ticks (suggestive, not exact).
129
+ The global default is `mg.get_setting("max_ticks")`.
130
+ - `tick_relabel` -- a callable applied to each generated label string,
131
+ after the contextual labelling has run. Use it to restyle labels
132
+ without losing the transition logic.
133
+ - `label_rotation` -- (`bar_plot` only) rotates the x-axis tick labels.
134
+
135
+ For example, to convert 4-digit year labels to 2-digit years:
136
+
137
+ ```python
138
+ import re
139
+
140
+ def two_digit_years(label: str) -> str:
141
+ """Shorten 4-digit years to 2 digits (e.g. 2024 -> 24)."""
142
+ return re.sub(r"\b(?:19|20)(\d{2})\b", r"\1", label)
143
+
144
+ # default labels: 2010 2012 2014 ... 2024 2026
145
+ # with tick_relabel: 10 12 14 ... 24 26
146
+ mg.line_plot_finalise(data, title="My Chart", tick_relabel=two_digit_years)
147
+ ```
148
+
149
+ Because `tick_relabel` operates on the label strings, this works
150
+ unchanged on quarterly or monthly axes too: a label such as `2024`
151
+ marking a year transition becomes `24`, while the `Q2`/`Mar` labels
152
+ between transitions pass through untouched.
153
+
154
+ These options are stashed on the matplotlib Axes when the plot is drawn,
155
+ and `finalise_plot()` honours them when it refreshes the tick labels
156
+ just before saving. Editing tick labels directly on the Axes (e.g. with
157
+ `set_xticklabels()`) does not survive that refresh -- use `tick_relabel`
158
+ instead.
159
+
160
+ Multi-Panel Figures
161
+ -------------------
162
+ `finalise_plot()` works on a single Axes. For a figure with several
163
+ panels, finalise each panel with `axes_only=True` (axes-level styling
164
+ only: titles, labels, legends), then make the last call a normal
165
+ `finalise_plot()` carrying the figure-level arguments (`suptitle`,
166
+ `lfooter`, `rfooter`, `figsize`, ...), which also saves and closes
167
+ the figure:
168
+
169
+ ```python
170
+ fig, (ax_left, ax_right) = plt.subplots(1, 2)
171
+ mg.line_plot(left_data, ax=ax_left)
172
+ mg.line_plot(right_data, ax=ax_right)
173
+ mg.finalise_plot(ax_left, title="Left Panel", ylabel="Index", axes_only=True)
174
+ mg.finalise_plot(
175
+ ax_right,
176
+ title="Right Panel",
177
+ ylabel="Index",
178
+ suptitle="Both Panels Together", # also used for the filename
179
+ lfooter="Australia. Seasonally adjusted.",
180
+ rfooter="Source: ABS",
181
+ figsize=(9, 4.5),
182
+ )
183
+ ```
184
+
97
185
  Convenience Finalisers
98
186
  ----------------------
99
187
  For every plot function, there is a `*_finalise()` variant that combines
@@ -52,8 +52,9 @@ All plot functions take a pandas Series or DataFrame with a PeriodIndex
52
52
  as the first argument and return a matplotlib Axes object. Keyword
53
53
  arguments control styling and behavior:
54
54
 
55
- - `bar_plot()` -- vertical bar plot (grouped or stacked) with intelligent
56
- PeriodIndex labeling
55
+ - `bar_plot()` -- bar plot (grouped or stacked) with intelligent
56
+ PeriodIndex labeling; `horizontal=True` plots categorical data as
57
+ horizontal bars (categories on the y-axis, values along the x-axis)
57
58
  - `fill_between_plot()` -- shaded region between two bounds (requires
58
59
  2-column DataFrame)
59
60
  - `growth_plot()` -- plots annual and periodic growth rates (requires
@@ -69,6 +70,25 @@ arguments control styling and behavior:
69
70
  - `summary_plot()` -- latest data point against historical range with
70
71
  z-score visualization
71
72
 
73
+ For ranked-category charts (states, industries, expenditure classes),
74
+ use `horizontal=True` with a string-indexed Series or DataFrame:
75
+
76
+ ```python
77
+ vacancies = vacancies.sort_values() # smallest at the bottom
78
+ mg.bar_plot_finalise(
79
+ vacancies,
80
+ horizontal=True,
81
+ annotate=True, # value labels at the bar ends
82
+ above=True,
83
+ x0=True, # zero line on the value axis
84
+ title="Job vacancies by industry",
85
+ xlabel="'000",
86
+ )
87
+ ```
88
+
89
+ `horizontal=True` is for categorical data: with a PeriodIndex it warns
90
+ and falls back to a vertical plot.
91
+
72
92
  Finalising Plots
73
93
  ----------------
74
94
  Once a plot is generated, finalise it with titles, labels, and save to file:
@@ -78,6 +98,74 @@ ax = mg.line_plot(data)
78
98
  mg.finalise_plot(ax, title="My Chart", ylabel="Units", tag="my_chart")
79
99
  ```
80
100
 
101
+ Axis Tick Labels
102
+ ----------------
103
+ For PeriodIndex data, x-axis tick labels are generated contextually:
104
+ the tick density is chosen to fit within `max_ticks`, and labels show
105
+ the period with years marked at transitions (e.g. a monthly axis shows
106
+ `Feb Mar ... 2024 ... Feb`, a quarterly axis shows `Q2 Q3 2025 Q2`).
107
+
108
+ Three keyword arguments control the labels on the period-indexed plot
109
+ functions (`line_plot`, `bar_plot`, `growth_plot`, `fill_between_plot`,
110
+ `run_plot`, and their `*_finalise` variants):
111
+
112
+ - `max_ticks` -- the maximum number of ticks (suggestive, not exact).
113
+ The global default is `mg.get_setting("max_ticks")`.
114
+ - `tick_relabel` -- a callable applied to each generated label string,
115
+ after the contextual labelling has run. Use it to restyle labels
116
+ without losing the transition logic.
117
+ - `label_rotation` -- (`bar_plot` only) rotates the x-axis tick labels.
118
+
119
+ For example, to convert 4-digit year labels to 2-digit years:
120
+
121
+ ```python
122
+ import re
123
+
124
+ def two_digit_years(label: str) -> str:
125
+ """Shorten 4-digit years to 2 digits (e.g. 2024 -> 24)."""
126
+ return re.sub(r"\b(?:19|20)(\d{2})\b", r"\1", label)
127
+
128
+ # default labels: 2010 2012 2014 ... 2024 2026
129
+ # with tick_relabel: 10 12 14 ... 24 26
130
+ mg.line_plot_finalise(data, title="My Chart", tick_relabel=two_digit_years)
131
+ ```
132
+
133
+ Because `tick_relabel` operates on the label strings, this works
134
+ unchanged on quarterly or monthly axes too: a label such as `2024`
135
+ marking a year transition becomes `24`, while the `Q2`/`Mar` labels
136
+ between transitions pass through untouched.
137
+
138
+ These options are stashed on the matplotlib Axes when the plot is drawn,
139
+ and `finalise_plot()` honours them when it refreshes the tick labels
140
+ just before saving. Editing tick labels directly on the Axes (e.g. with
141
+ `set_xticklabels()`) does not survive that refresh -- use `tick_relabel`
142
+ instead.
143
+
144
+ Multi-Panel Figures
145
+ -------------------
146
+ `finalise_plot()` works on a single Axes. For a figure with several
147
+ panels, finalise each panel with `axes_only=True` (axes-level styling
148
+ only: titles, labels, legends), then make the last call a normal
149
+ `finalise_plot()` carrying the figure-level arguments (`suptitle`,
150
+ `lfooter`, `rfooter`, `figsize`, ...), which also saves and closes
151
+ the figure:
152
+
153
+ ```python
154
+ fig, (ax_left, ax_right) = plt.subplots(1, 2)
155
+ mg.line_plot(left_data, ax=ax_left)
156
+ mg.line_plot(right_data, ax=ax_right)
157
+ mg.finalise_plot(ax_left, title="Left Panel", ylabel="Index", axes_only=True)
158
+ mg.finalise_plot(
159
+ ax_right,
160
+ title="Right Panel",
161
+ ylabel="Index",
162
+ suptitle="Both Panels Together", # also used for the filename
163
+ lfooter="Australia. Seasonally adjusted.",
164
+ rfooter="Source: ABS",
165
+ figsize=(9, 4.5),
166
+ )
167
+ ```
168
+
81
169
  Convenience Finalisers
82
170
  ----------------------
83
171
  For every plot function, there is a `*_finalise()` variant that combines