Search code examples
pythonmanim

Why is ManimCE plotting a different graph than the one provided?


I'm trying to create a graph for the function (1+1/x)^x.

I wrote it in python like this:

def func(x):
    return pow(1+(1/x),x)

I then plotted it like this:

graph = axes.plot(lambda x: func(x), color=BLUE, stroke_width=2, x_range=[0,X_MAX])

(X_MAX is a variable that equals 1000)

but for some reason Manim is plotting something else.

When I plotted the function in Desmos I got this graph:

And Manim gave me this one:

(I know the scales are different the main focus is the hump at the top)


Solution

  • It is the default smoothing that causes these weird oscillations; basically this happens because the function changes too fast in a (relatively) small interval.

    Try either passing use_smoothing=False to your call of plot -- and/or alternatively, try refining the step size by passing a third number to the x_range list.