Skip to content

Add support for axes.Axes._tikzplotlib_anchors #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

st--
Copy link

@st-- st-- commented Sep 23, 2022

The documentation mentions support for a _tikzplotlib_anchors attribute on matplotlib Axes() objects to add custom anchors in the plot (very useful to refer back to from custom tikz code outside the auto-generated one, e.g. to add additional content from the outside). However, this isn't actually supported in the code. This PR adds a minimal implementation; I'd be happy to discuss how to improve it!

Example Python code:

import matplotlib.pyplot as plt
plt.plot([1,2,3], [4,-2,3])
ax = plt.gca()
ax._tikzplotlib_anchors = [((1.5, 2.5), "foo")]
import tikzplotlib as tikz
tikz.save("test.tex")

Resulting generated output:

% This file was created with tikzplotlib v0.10.1.
\begin{tikzpicture}

\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{steelblue31119180}{RGB}{31,119,180}

\begin{axis}[
tick align=outside,
tick pos=left,
x grid style={darkgray176},
xmin=0.9, xmax=3.1,
xtick style={color=black},
y grid style={darkgray176},
ymin=-2.3, ymax=4.3,
ytick style={color=black}
]
\addplot [semithick, steelblue31119180]
table {%
1 4
2 -2
3 3
};
\coordinate (foo) at (1.5,2.5);
\end{axis}

\end{tikzpicture}

Note the additional \coordinate (foo) at (1.5,2.5); line.

@st--
Copy link
Author

st-- commented Sep 23, 2022

NB- I'm not sure about calling it _tikzplotlib_anchors, I just went with that as it was in the docstring, but given that it's not implemented and no-one's been able to use it before, how about calling it _tikzplotlib_coordinates or _tikzplotlib_additional_coordinates instead?

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.

1 participant