manim
manim copied to clipboard
Error in Cosine Function Graph
I am trying to create a cosine graph using Manim but it was different from the actual graph. How should I edit my code to make it the actual graph. Thanks in advance. Code:
from manim import *
from numpy import cos
class CreateGraph(GraphScene):
def __init__(self, **kwargs):
GraphScene.__init__(
self,
x_min=-5,
x_max=5,
y_min=-5,
y_max=5,
graph_origin=ORIGIN,
axes_color=GREEN)
def construct(self):
# Create Graph
self.setup_axes(animate=True)
f1 = self.get_graph(lambda x: cos(1/x) , x_min=-4, x_max=4)
# Construct the Figures
self.play(ShowCreation(f1))
self.wait(1)
Error:
Environment
OS System: Windows 10 manim version: master <V.6 Community Version> python version: .3.7.0
Setting the t_range
parameter to np.array([0, 1, 0.0001])
and discontinuities
to [0]
fixed it for me. Rendering time was increased a bit though. As you make the step size in t_range
smaller and smaller, the graph will become more accurate, but rendering time will increase.
f1 = self.get_graph(lambda x: np.cos(1/x) , x_min=-4, x_max=4, t_range = np.array([0, 1, 0.0001]), discontinuities=[0])
Hope this helps! :D
I believe proper graphing software intelligently uses different step sizes for different parts of the graph. Unfortunately, we still use a fairly naive plotting method.
I believe this should be open until we can intelligently graph functions like these.