3b1b / manim

Animation engine for explanatory math videos
MIT License
60.27k stars 5.69k forks source link

gráfico de salida incorrecto #2014

Open elin-geniero opened 1 year ago

elin-geniero commented 1 year ago

Quiero graficar esta función: f(x)=(cos(x))/x, pero el gráfico de salida no es el que corresponde utilizo la última versión v0.17.3 con python 3.11.3

Este es el código:

`class Ejemplo1(Scene): def construct(self): axes = Axes( y_range = [-10.9, 10.9, 1], x_range = [-2,2,1], )

    label=axes.get_axis_labels(MathTex('x').scale(1.5), MathTex('f(x)').scale(1.2))

    color1="#4E6C50"

    axes.add_coordinates()

    grafico = axes.plot(
        lambda x: np.divide(np.cos(x),x),
        color = YELLOW,
        x_range=[-2,2])

    t = MathTex(r"f(x)=\frac{cos(x)}{x}", font_size=70).shift(UP*1.2,RIGHT*2)

    background = ImageMobject('background').scale(50).set_opacity(1)

    point = axes.c2p(0, 0)

    dot1= Dot(point, radius=0.1, fill_opacity=0, stroke_width=5)
    dot= Dot(point, radius=0.1, color=color1, stroke_width=5)

    self.add(background, axes, grafico, t, label,dot,dot1)`

    Y la gráfica que recibo de salida es esta

imagen

Pero debería ser similar a esta

imagen

¿qué estoy haciendo mal?

tagomatech commented 1 year ago

Hi elin-geniero Can you please try out the following piece of code?

from manimlib import *

class Ejemplo1(Scene):
    def construct(self):

        axes = Axes(
        y_range = [-10.9, 10.9, 1.0],
        x_range = [-2.0, 2.0 ,1.0]
        )

        axes.add_coordinate_labels()

        grafico = axes.get_graph(
            lambda x: np.divide(np.cos(x),x),
            color = YELLOW,
            x_range=[-2.0, 2.0])

        point = axes.c2p(0.0, 0.0)

        dot1= Dot(point, radius=0.1, fill_opacity=0.0, stroke_width=5)

        dot= Dot(point, radius=0.1, color="#4E6C50", stroke_width=5)

        self.add(axes, grafico, dot, dot1)

I had to simplify your original code snippet (to keep away anything LaTex-related), but it shows the graph you expected.