# pgfplots function which touches the edges of the plot

I need to plot the constant y = pi function with the plot touching both sides of the plot.

I have had a search through the pgfplots manual without much luck. I have tried \addplot{3.141...} which produces a small line spanning very little of the x axis, and manually plotting points for the range of my graph.

-
You can use the addplot command as you are currently doing. Just add enlargelimits=false as an option to your axis environments. –  Roelof Spijker Feb 7 '12 at 15:39
While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem. This would also ensure that the solutions provided would be compatible with the way you are using them. –  Peter Grill Feb 7 '12 at 16:11
How about \addplot expression[domain=-10:10]{pi};  –  cmhughes Feb 7 '12 at 16:40

I see two ways to achieve what you want, depending on what you mean by "touching both sides of the plot".

You can add an extra y tick. Or, you can add a plot that is constant either by using coordinates or function. The coordinates one needs the xmin and xmax to be specified.

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel={$x$},
ylabel={$\arctan(x)$},
extra y ticks={0.785},
extra y tick labels={$\pi/4$},
extra y tick style={grid=major},
minor y tick num=1,
domain=-5:5,
samples=100]
\end{axis}
\end{tikzpicture}
\end{document}


-
Just what I was after, Cheers. –  Jonathan Evans Feb 7 '12 at 18:23

You have either of the following two as an option:

\begin{axis}
\begin{pgfplotsinterruptdatabb}
\end{pgfplotsinterruptdatabb}
\end{axis}


or

\begin{axis}
\addplot[forget plot,update limits=false] coordinates {(-16000,3.14) (16000,3.14)};
\end{axis}


The first I would prefer. You can then easily do:

\newcommand\addplotpi[1][]{
\begin{pgfplotsinterruptdatabb}

and simply use that in every axis environment you wish to utilize it in.
The forget plot allows you to add it in the beginning of an axis environment without disturbing the color-lists and legends.
The only thing you should worry about is the lower and upper limit of x`. But just do it large enough so that it wont bother you! :)