# Incorrect results from simple Plot?

I came across this bizarre behaviour whilst noodling around - a change in 'Plot' results...

testPlot1 = Plot[Log[HarmonicNumber[n]],
{n, 1, 5}];
testPlot2 = Plot[Log[HarmonicNumber[n]],
{n, 1, 43}];
Show[testPlot1, PlotRange -> {{0, 5}, {0, 1}}]
Show[testPlot2, PlotRange -> {{0, 5}, {0, 1}}]


The line moves away from the origin, crossing the n line increasingly far to the right, and giving no negative output - it just vanishes at the n line.

At first I thought it happened exclusively for n>=43, but actually, it seems to happen randomly for different domain ranges. Using Table gives the correct result.

What's going wrong, and how do I fix it?

• In the first case, you are not setting PlotRange at all, but in Show you are using specific PlotRange. So why do you expect the results to look the same? – Nasser Jun 17 at 12:54

## 2 Answers

Use the plotoption AxesOrigin->{0,0}:

testPlot1 =Plot[Log[HarmonicNumber[n]], {n, 1, 5}, AxesOrigin -> {0, 0}] ;
testPlot2 =Plot[Log[HarmonicNumber[n]], {n, 1, 43}, AxesOrigin -> {0, 0}] ;

Show[testPlot1, PlotRange -> {{0, 5}, {0, 1}}] Show[testPlot2, PlotRange -> {{0, 5}, {0, 1}}]


same plot in both cases!

• Hi @Ulirch. Do you mean AxesOrigin? (With an 'e') – Richard Burke-Ward Jun 17 at 12:49
• Sorry: Yes I meant AxesOrigin – Ulrich Neumann Jun 17 at 12:54
• I'm afraid that doesn't seem to work.If I specify AxesOrigin -> {0, 0} for testPlot2, the curve still hits the n line at n=1 - which is mathematcally incorrect. If I use it for testPlot1 and testPlot2 the curve still intersects the n line in different places for each plot. Mathematica is changing the actual values of the plot, not where the axes are. – Richard Burke-Ward Jun 17 at 12:55
• I would expect Log[HarmonicNumber]==0 – Ulrich Neumann Jun 17 at 13:02
• You're right @Ulrich (and that was what I expected too). I must have entered something wrongly. Much appreciated. – Richard Burke-Ward Jun 17 at 13:03

Another solution: increase the PlotPoints in testPlot2:

testPlot1 = Plot[Log[HarmonicNumber[n]], {n, 1, 5}];
testPlot2 =
Plot[Log[HarmonicNumber[n]], {n, 1, 43}, PlotPoints -> 100];
Show[testPlot1, PlotRange -> {{0, 5}, {0, 1}}]
Show[testPlot2, PlotRange -> {{0, 5}, {0, 1}}]  • Hi @Chris. Also good. I have ticked Ulrich's because he got there first, but I appreciate the suggestion. – Richard Burke-Ward Jun 17 at 13:15
• No prob -- nothing stops you from upvoting multiple answers BTW :) – Chris K Jun 17 at 13:24
• The magic number of PlotPoints must be >5, but the option PlotPoints -> {Automatic, {1}}] works to#o! – Ulrich Neumann Jun 17 at 13:37