Skip to content

Add support for AnchoredText conversion to TikZ#62

Open
krishna-ji wants to merge 1 commit intoErwindeGelder:mainfrom
krishna-ji:fix/issue-53-anchored-text
Open

Add support for AnchoredText conversion to TikZ#62
krishna-ji wants to merge 1 commit intoErwindeGelder:mainfrom
krishna-ji:fix/issue-53-anchored-text

Conversation

@krishna-ji
Copy link
Copy Markdown
Collaborator

Fixes #53

Problem

AnchoredText objects from matplotlib.offsetbox were silently ignored during conversion, producing a warning:
Don't know how to handle artist AnchoredText(...)

Solution

  • Added AnchoredText to the dispatch loop in _save.py::_recurse() (placed before Text to ensure correct isinstance matching order).
  • Implemented draw_anchored_text() in _text.py that:
    • Extracts Text children from the AnchoredText's TextArea
    • Maps matplotlib's loc codes (1–10) to tikz (rel axis cs:x,y) positions with appropriate anchors via _LOC_TO_TIKZ
    • Handles bbox patch properties (fill color, edge color, line width)
    • Handles font size, weight, and color

Test

Added test_anchored_text.py with a matching reference file. All existing tests continue to pass (114/114).

Validation

  • tox -e lint (ruff format, ruff check, mypy): all pass
  • tox -e py314 (pytest): 114/114 pass

AnchoredText objects from matplotlib.offsetbox were previously ignored during
conversion, producing a 'Don't know how to handle' warning. Now they are
converted to TikZ \draw nodes with correct positioning and styling:

- Map matplotlib loc codes (1-10) to rel axis cs coordinates with pgfplots
  anchors (e.g., upper left -> rel axis cs:0.02,0.98, anchor=north west)
- Handle bounding box patch (fill, border, line width)
- Handle font properties (size scaling, bold, italic, color)
- Handle invisible patches (no box drawn)
- Handle multiline text

Added test_anchored_text.py with reference file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

textboxes generated with AnchoredText() are not converted into tikz by matplot2tikz

1 participant