10

I would like to know if there is a way to specify axis cs to be the default coordinate system inside a plot in PGFPlots, so I don't have to type axis cs: in front of every coordinate pair. Here's a MWE that shows what I mean (the actual plot is irrelevant).

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
 \begin{axis}[
              xmin=0,
              xmax=80,
              ymin=0,
              ymax=80,
              grid=major,
             ]
  \fill [green, opacity=0.5] (axis cs:14,14) -- (axis cs:80,47) -- (axis cs:80,80) -- (axis cs:47,80) -- cycle;
  \fill [red, opacity=0.5] (0,0) -- (axis cs:80,0) -- (axis cs:80,47) -- (axis cs:14,14) -- (axis cs:47,80) -- (axis cs:0,80) -- cycle;
  \draw [thick] (axis cs:47,80) -- (axis cs:14,14) -- (axis cs:80,47);
 \end{axis}
\end{tikzpicture}

\end{document}
12

The current stable version of pgfplots is version 1.11 (released August 2014). It supports this if you write \pgfplotsset{compat=1.11} into your preamble. Without this statement, it will remain compatible with the old behavior.

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
 \begin{axis}[
              xmin=0,
              xmax=80,
              ymin=0,
              ymax=80,
              grid=major,
             ]
  \fill [green, opacity=0.5] (14,14) -- (80,47) -- (80,80) -- (47,80) -- cycle;
  \fill [red, opacity=0.5] (0,0) -- (80,0) -- (80,47) -- (14,14) -- (47,80) -- (0,80) -- cycle;
  \draw [thick] (47,80) -- (14,14) -- (80,47);
 \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • So, axis cs is the default coordinate system in the current version of pgfplots? – nemarona Oct 22 '14 at 17:12
  • 5
    Right. Provided you say \pgfplotsset{compat=1.11}. – Christian Feuersänger Oct 22 '14 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.