Graphics, Figures & Tablespgfplots | Shading certain parts of the coordinate grid

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
niles
Posts: 92
Joined: Mon Dec 01, 2008 9:35 pm

pgfplots | Shading certain parts of the coordinate grid

Post by niles »

Hi

Please see the MWE:

Code: Select all

\documentclass{article}

\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both]
\addplot3 coordinates {(0,0,0) (0,0.5,1) (0,1,0)};
\end{axis}
\end{tikzpicture}
\end{document}
What I am trying to do is to shade certain rectangles in the coordinate-grid. Specifically the strip/area I am talking about is

-0.5..0 on the x-axis
0..1 on the y-axis
0..1 on the z-axis

and it should be shaded in e.g. grey such as to show what area I am referring to in the text.

I couldn't seem to find an example of this in the manual. Thanks for any help/hints in advance.

Best,
Niles.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

pgfplots | Shading certain parts of the coordinate grid

Post by cgnieder »

Hi Niles,

I probably haven't understood which region you wanted to fill but I think this'll help you anyway. By using the coordinate system axis cs you have access to points of the axis environment and can use normal tikz:

Code: Select all

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
 \begin{axis}[grid=both]
  \draw[fill=gray!50,opacity=.7]
    (axis cs:-.5,0,0) -- (axis cs:-.5,0,1) -- (axis cs:-.5,1,1) -- (axis cs:-.5,1,0) -- cycle ;
  \draw[fill=gray!50,opacity=.7]
    (axis cs:-.5,0,0) -- (axis cs:0,0,0) -- (axis cs:0,1,0) -- (axis cs:-.5,1,0) -- cycle ;
  \addplot3 coordinates {(0,0,0) (0,0.5,1) (0,1,0)};
 \end{axis}
\end{tikzpicture}

\end{document}
Regards
site moderator & package author
niles
Posts: 92
Joined: Mon Dec 01, 2008 9:35 pm

Re: pgfplots | Shading certain parts of the coordinate grid

Post by niles »

Thanks, it works!
Post Reply