Why my code only show half ? how can can I improve it ? and I want my code can be achieved like that videolike that
below picture is my result
That’s my result
it only show half
`import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from math import e, pi, sin
def f(x, a):
x = np.clip(x, -np.sqrt(np.pi), np.sqrt(np.pi))
return x**(2/3) + e/3 * np.maximum (0, (pi - x**2)**0.5) * np.sin(a * pi * x)
fig, ax = plt.subplots()
x = np.linspace(-2, 2, 400)
line, = ax.plot(x, f(x, 0), lw=2, color='red')
ax.set_xlim([-2, 2])
ax.set_ylim([-1.5, 2.5])
ax.set_xlabel('x')
ax.set_ylabel('f(x)')
ax.set_title('f(x) = x^(2/3) + e/3*(π-x^2)^1/2*sin(a*π*x)')
def update(a):
line.set_ydata(f(x, a))
ax.set_title(f'f(x) = x^(2/3) + e/3*(π-x^2)^1/2*sin({a:.1f}πx)')
return line,
frames = np.arange(0, 20, 0.05)
ani = animation.FuncAnimation(fig, update, frames=frames, interval=10, blit=True)
plt.show()`
I can’t find how to improve it i’m new about matplotlib
New contributor
Roche Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.