TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

The following MWE



        \begin{axis}[ylabel=Y-Axis, xlabel=X-Axis, xmin=0.000, xmax=0.9, ymin=0, ymax=12, clip=false, yticklabel pos=right, ylabel near ticks]
            \addplot[mark=none, domain=0.000:0.9, thick] {-ln(x/#1^2)/ln(#1)}; %Varying R values


yields the following graph

Graph in which the plots do not make it to the X-axis

Mathematically, these lines should extend to infinity when they reach x=0 at the left-hand side of the box.

What is the "best way" to get these lines close to the edge of the box or otherwise fill them in so they are not cut-off?

share|improve this question
up vote 7 down vote accepted

You will need to use the samples option to addplot and increase the number:

\addplot[mark=none, domain=0.000:0.9, thick,samples=40] {-ln(x/#1^2)/ln(#1)} node [pos=0,left] {$R=#1$}; %Varying R values

here 40 is just a wild guess.

Edit, actually a sample value of 500 is probably more what you want as 40 doesn't give you anything that different.

with a sample value of 500 you get this:

plot using the <code>sample=500</code> solution

Edit2: Following @Jake suggestion, you can indeed use the samples at option to addplot to specify the intervals in x values which need more definition/samples. In this particular case, samples at={0.001,0.002,...,0.01,0.02,...,0.9} gives you a sample every 0.001 between 0.001 and 0.01 and a sample of 0.01 between 0.01 and 0.9. This is of course a manual setting and will have to be adapted to your different plots but in this case it works particularly well. In addition the smooth option with get rid of most of the raggedness of the plot:

plotting using the <code>sample at={}, smooth</code> solution

The advantage of the samples=500 solution is that it is fairly generic across plots but it does require a lot more calculations which add to compilation time but may be the best solution if you are plotting things which varies a lot across the entire x range (tan(x) for example).

share|improve this answer
For problematic functions like this, I find the samples at feature quite useful, which allows you to specify sampling points explicitly. You can mix list and ... notation, so in this case you could say something like samples at={0.001,0.002,...,0.01,0.02,...,0.9}, which would plot the function with about 60 samples, with a higher sampling density near the start. – Jake Jul 18 '12 at 22:39
Indeed that is probably better in general and will be much faster to compile. Although the end result isn't as smooth looking – ArTourter Jul 18 '12 at 22:52
You can add smooth to the \addplot options to smooth out the corners. While mathematically not exact, the result should be accurate enough for most purposes. – Jake Jul 18 '12 at 22:58
Ah indeed, learn new things every day! – ArTourter Jul 18 '12 at 23:02
@richard, you are indeed correct. I had not copy/pasted my code but simply retyped it, albeit badly. Sorry about this. Alan Nunn has accepted your edits before I had the time to. – ArTourter Jul 19 '12 at 16:45

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.