manim icon indicating copy to clipboard operation
manim copied to clipboard

Plotting issue

Open harshpundhir opened this issue 8 months ago • 1 comments

Description of bug / unexpected behavior

error -> Exception: Not sure how you reached here, please file a bug report at https://github.com/ManimCommunity/manim/issues/new/choose

Expected behavior

The curve tangent motion

How to reproduce the issue

Code for reproducing the problem
class MathScene3(Scene):
    def construct(self):
        ax = Axes()
        sine = ax.plot(np.log, color=RED)
        alpha = ValueTracker(0)
        point = always_redraw(
            lambda: Dot(
                sine.point_from_proportion(alpha.get_value()),
                color=BLUE
            )
        )
        tangent = always_redraw(
            lambda: TangentLine(
                sine,
                alpha=alpha.get_value(),
                color=BLUE_A,
                length=4
            )
        )
        self.add(ax, sine, point, tangent)
        self.play(alpha.animate.set_value(1), rate_func=linear, run_time=4)

Additional media files

Images/GIFs

Logs

Terminal output
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR

System specifications

System Details
  • OS (with version, macOS sequoia
  • RAM:
  • Python version (python/py/python3 --version):
  • Installed modules (provide output from pip list):
Exception: Not sure how you reached here, please file a bug report at https://github.com/ManimCommunity/manim/issues/new/choose
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020):
  • Installed LaTeX packages:

Additional comments

harshpundhir avatar Apr 07 '25 17:04 harshpundhir

The logarithmic function np.log(x) is not defined for values of x <= 0 Apparently the .plot function is not evaluated before you are trying to access the starting point.

Just set an appropriate interval for the plot:

class MathScene3(Scene):
    def construct(self):
        ax = Axes()
        sine = ax.plot(np.log, color=RED, x_range=[1e-2,6,1e-2])
        alpha = ValueTracker(0)
        point = always_redraw(
            lambda: Dot(
                sine.point_from_proportion(alpha.get_value()),
                color=BLUE
            )
        )
        tangent = always_redraw(
            lambda: TangentLine(
                sine,
                alpha=alpha.get_value(),
                color=BLUE_A,
                length=4
            )
        )
        self.add(ax, sine, point, tangent)
        self.play(alpha.animate.set_value(1), rate_func=linear, run_time=4)

https://github.com/user-attachments/assets/c656ef6b-bab1-4b49-adda-a8338f63b246

uwezi avatar Apr 07 '25 17:04 uwezi