Skip to content

Commit b6a992a

Browse files
Jammy2211claude
authored andcommitted
Add ticks.minus_in_math config for math minus sign in arcsec labels
`_arcsec_labels` emitted an ASCII hyphen (U+002D) for negative tick values. Add a `ticks.minus_in_math` config flag (default false) that, when true, renders negatives with the Unicode/math minus (U+2212, matplotlib's own minus glyph), e.g. −0.″05 instead of -0.″05. Applies to both the suffix and symbol-over-decimal label formats and is the single tick-label chokepoint used by all 2D plot panels. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 59a7802 commit b6a992a

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

autoarray/config/visualize/general.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ticks:
2222
extent_factor_2d: 0.75 # Fraction of half-extent used for 2D tick positions (< 1.0 pulls ticks inward from edges).
2323
number_of_ticks_2d: 3 # Number of ticks on each spatial axis of 2D plots.
2424
symbol_over_decimal: false # If true, place the arcsec double-prime symbol over the decimal point, e.g. 3.″8, instead of after the value, e.g. 3.8".
25+
minus_in_math: false # If true, render negative tick labels with the Unicode/math minus sign (U+2212) instead of an ASCII hyphen (U+002D), e.g. −0.″05 instead of -0.″05.
2526
contour:
2627
total_contours: 10 # Number of contour levels drawn over log10 (and explicit linear) plots.
2728
include_values: true # Whether to label each contour line with its value.

autoarray/plot/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,14 @@ def _arcsec_labels(ticks) -> List[str]:
911911
``ticks.symbol_over_decimal`` is true, labels use the double-prime arcsecond
912912
symbol and decimal labels place it over the decimal point, e.g. ``3.″8``.
913913
"""
914+
minus_in_math = _conf_ticks_flag("minus_in_math", False)
915+
916+
def _fmt_minus(label: str) -> str:
917+
# Replace the ASCII hyphen-minus (U+002D) with the Unicode/math minus
918+
# (U+2212, matplotlib's own minus glyph) so negative arcsecond labels
919+
# render with a proper minus sign rather than a hyphen.
920+
return label.replace("-", "−") if minus_in_math else label
921+
914922
labels = [f'{v:g}' for v in ticks]
915923
if any("." in label for label in labels):
916924
labels = [
@@ -922,11 +930,11 @@ def _arcsec_labels(ticks) -> List[str]:
922930
for label in labels:
923931
if "." in label:
924932
int_part, frac_part = label.split(".", 1)
925-
symbol_labels.append(f"{int_part}.″{frac_part}")
933+
symbol_labels.append(_fmt_minus(f"{int_part}.″{frac_part}"))
926934
else:
927-
symbol_labels.append(f"{label}″")
935+
symbol_labels.append(_fmt_minus(f"{label}″"))
928936
return symbol_labels
929-
return [f'{label}"' for label in labels]
937+
return [_fmt_minus(f'{label}"') for label in labels]
930938

931939

932940
def apply_extent(

test_autoarray/plot/test_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,29 @@ def test_arcsec_labels_mixed_integer_and_decimal_default():
5050
assert _arcsec_labels([-2.1, -0.044, 2.0]) == ['-2.1"', '-0.044"', '2.0"']
5151
finally:
5252
ticks["symbol_over_decimal"] = original
53+
54+
55+
def test_arcsec_labels_minus_in_math():
56+
ticks = conf.instance["visualize"]["general"]["ticks"]
57+
original_symbol = ticks.get("symbol_over_decimal", False)
58+
original_minus = ticks.get("minus_in_math", False)
59+
try:
60+
ticks["minus_in_math"] = True
61+
62+
# Suffix format: the ASCII hyphen (U+002D) becomes the math minus (U+2212).
63+
ticks["symbol_over_decimal"] = False
64+
assert _arcsec_labels([-2.1, -0.044, 2.0]) == ["−2.1\"", "−0.044\"", "2.0\""]
65+
66+
# Symbol-over-decimal format also uses the math minus.
67+
ticks["symbol_over_decimal"] = True
68+
assert _arcsec_labels([-2.1, -0.044, 2.0]) == ["−2.″1", "−0.″044", "2.″0"]
69+
70+
# Positive-only tick sets are unchanged.
71+
assert _arcsec_labels([0.13, 1.95]) == ["0.″13", "1.″95"]
72+
73+
# The emitted minus really is U+2212, not the ASCII hyphen U+002D.
74+
label = _arcsec_labels([-0.5])[0]
75+
assert "−" in label and "-" not in label
76+
finally:
77+
ticks["symbol_over_decimal"] = original_symbol
78+
ticks["minus_in_math"] = original_minus

0 commit comments

Comments
 (0)