0

I'm trying to simulate a double pendulum using C and python. The following code uses an "animate" function to simulate the trajectory using arrays of value.

However, when I try to launch it, it gives me the following error: "AttributeError: 'AxesSubplot' object has no attribute 'set_facecolor'"

It isn't the first time i've had this error, can anyone please tell me where it comes from & how i can fix it?

Here is the code:


import numpy as np
import pylab as plt
import matplotlib.pyplot as plt
from matplotlib import animation


# M1 Trajectory Data
DonneesM1 = np.loadtxt('TrajectoireM1.txt')
Xm1 = DonneesM1[:,0]
Ym1 = DonneesM1[:,1]

# M2 Trajectory Data
DonneesM2 = np.loadtxt('TrajectoireM2.txt')
Xm2 = DonneesM2[:,0]
Ym2 = DonneesM2[:,1]

def animate(i):
    ln1.set_data([0, Xm1[i], Xm2[i]], [0, Ym1[i], Ym2[i]])
    
fig, ax = plt.subplots(1,1, figsize=(8,8))
ax.set_facecolor('black')
ax.get_xaxis().set_ticks([])    # enable this to hide x axis ticks
ax.get_yaxis().set_ticks([])    # enable this to hide y axis ticks
ln1, = plt.plot([], [], 'ro--', lw=3, markersize=8)
ax.set_ylim(-4,4)
ax.set_xlim(-4,4)
ani = animation.FuncAnimation(fig, animate, frames=1000, interval=50)
ani.save('pen.gif',writer='pillow',fps=25)

Ray
  • 1
  • Welcome to SO! What happens when you run a new session or a file with just the following three lines? ```import matplotlib.pyplot as plt```, ```fig, ax = plt.subplots()```, and ```ax.set_facecolor("black")``` – fdireito Nov 30 '22 at 12:27

0 Answers0