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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
up vote 2 down vote accepted

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.

    extra y ticks={0.785},
    extra y tick labels={$\pi/4$},
    extra y tick style={grid=major},
    minor y tick num=1,
    \addplot+[no marks] function {atan(x)};
    \addplot+[no marks] function {pi/2};
    \addplot+[no marks] coordinates {(-5,pi) (5,pi)};

enter image description here

share|improve this answer
Just what I was after, Cheers. – Jonathan Evans Feb 7 '12 at 18:23

You have either of the following two as an option:

    \addplot[forget plot] coordinates {(-16000,3.14) (16000,3.14)};


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

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

    \addplot[forget plot,#1] coordinates {(-16000,3.14) (16000,3.14)};

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! :)

share|improve this answer

Your Answer


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.