Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/matplot2tikz/_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def _get_tikz_pos(data: TikzData, obj: Text, content: list[str]) -> str:
if isinstance(pos, str):
return pos
if obj.axes:
# If the coordinates are relative to an axis, use `axis cs`.
# Check if the text uses axes-relative coordinates (transform=ax.transAxes).
# In that case, use `rel axis cs` instead of `axis cs`.
transform = obj.get_transform()
if transform == obj.axes.transAxes:
return f"(rel axis cs:{pos[0]:{data.float_format}},{pos[1]:{data.float_format}})"
return f"(axis cs:{pos[0]:{data.float_format}},{pos[1]:{data.float_format}})"
# relative to the entire figure, it's a getting a littler harder. See
# <http://tex.stackexchange.com/a/274902/13262> for a solution to the
Expand Down
8 changes: 4 additions & 4 deletions tests/test_fancybox_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
--(axis cs:0.2,0.4)
.. controls (axis cs:0.2,0.33333333) and (axis cs:0.23333333,0.3) .. (axis cs:0.3,0.3)
--cycle;
\draw (axis cs:0.1,0.8) node[
\draw (rel axis cs:0.1,0.8) node[
scale=0.5,
anchor=base west,
text=black,
Expand Down Expand Up @@ -63,7 +63,7 @@
--(axis cs:0.2,0.5)
.. controls (axis cs:0.2,0.36666667) and (axis cs:0.26666667,0.3) .. (axis cs:0.4,0.3)
--cycle;
\draw (axis cs:0.1,0.8) node[
\draw (rel axis cs:0.1,0.8) node[
scale=0.5,
anchor=base west,
text=black,
Expand Down Expand Up @@ -99,7 +99,7 @@
--(axis cs:0.1,0.4)
.. controls (axis cs:0.1,0.26666667) and (axis cs:0.16666667,0.2) .. (axis cs:0.3,0.2)
--cycle;
\draw (axis cs:0.1,0.8) node[
\draw (rel axis cs:0.1,0.8) node[
scale=0.5,
anchor=base west,
text=black,
Expand Down Expand Up @@ -135,7 +135,7 @@
--(axis cs:0,0.4)
.. controls (axis cs:0,0.3) and (axis cs:0.1,0.25) .. (axis cs:0.3,0.25)
--cycle;
\draw (axis cs:0.1,0.8) node[
\draw (rel axis cs:0.1,0.8) node[
scale=0.5,
anchor=base west,
text=black,
Expand Down
Loading