Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to fill quadrant three and want to use axis equal=true. However, using this setting changes the minimum value of x. How do I adjust this to fill the entire quadrant independent of axis equal=true or axis equal=false.

The MWE below produces the result I want, but not if I uncomment the axis equal=true line.

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}

\newcommand*{\XAxisMin}{-4.5}
\newcommand*{\XAxisMax}{4.5}
\newcommand*{\YAxisMin}{-4.5}
\newcommand*{\YAxisMax}{4.5}

\begin{axis}[%axis equal=true,
    axis y line=center, axis x line=middle, axis on top=true,
    xmin=\XAxisMin, xmax=\XAxisMax, ymin=\YAxisMin, ymax=\YAxisMax, 
] 

\fill[red!40]
    (axis cs:\XAxisMin,\YAxisMin) -- 
    (axis cs:0.0,\YAxisMin) -- 
    (axis cs:0.0,0.0) -- 
    (axis cs:\XAxisMin,0.0) -- 
    cycle;

% Based on Jake's solution, this should have worked, but produces identical results for me (PGFversion: 2.10)
%        \fill[green!40]
%       (axis cs:\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymin}) -- 
%       (axis cs:0.0,\pgfkeysvalueof{/pgfplots/ymin}) -- 
%       (axis cs:0.0,0.0) -- 
%       (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0.0) -- 
%       cycle;


\end{axis} 
\end{tikzpicture} 
\end{document}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Threeapproaches:

  • Use the rel axis cs coordinate system, which places (0,0) in the lower left corner of the plot and (1,1) in the upper right
  • Use the anchors current axis.left of origin and current axis.below origin, which are the projections of the axis origin on the left and lower plot edge, respectively
  • or, if you're using the CVS version of PGFplots read the current value of xmin and xmax using \pgfkeysvalueof{/pgfplots/xmin}

Example:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}

\newcommand*{\XAxisMin}{-4.5}
\newcommand*{\XAxisMax}{4.5}
\newcommand*{\YAxisMin}{-4.5}
\newcommand*{\YAxisMax}{4.5}

\begin{axis}[axis equal=true,
    axis y line=center, axis x line=middle, axis on top=true,
    xmin=\XAxisMin, xmax=\XAxisMax, ymin=\YAxisMin, ymax=\YAxisMax, 
] 

\fill[orange!50] (axis cs:0,0) rectangle (rel axis cs:1,1);

\fill[green!70!black] (current axis.right of origin) rectangle (current axis.below origin);

\fill[blue!50]
    (axis cs:\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax})
    rectangle (axis cs:0,0) node [pos=0.5,text=white] {CVS only};

\end{axis} 
\end{tikzpicture} 
\end{document}

pgfplots with coloured quadrants

share|improve this answer
    
Updated MWE to use pgfkeysvalueof but this produces identical results. –  Peter Grill Jul 11 '11 at 22:56
    
Oh sorry, it seems the \pgfkeysvalueof approach only works in the CVS version of PGFplots. The first approach should work with the current version though. –  Jake Jul 11 '11 at 23:28
    
Do the first two approaches (rel axis cs and current axis.right of origin) not work in your case? –  Jake Jul 27 '11 at 2:26
    
Yep, all three work now that I updated to the latest 2010 TeXLive. –  Peter Grill Jul 27 '11 at 3:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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