0
import numpy as np
import matplotlib.pyplot as plt
from io import BytesIO
from PIL import Image

r = 18
h = 1.7
num_of_steps = 1000
emp = 3
time = np.arange(0, 100, 0.4)
phi = []
theta = []
Amp = np.pi/6
fphi = 4
ftheta = 9
pics = []
r1 = 16

for j in time:
    kampas = np.radians(2*np.pi*fphi*j)
    kitaskampas = Amp*(np.sin(np.radians(2*np.pi*ftheta*j)))
    phi.append(kampas)
    theta.append(kitaskampas)

theta = 0.524
#print(theta)
x = r * np.cos(phi)
y = r * np.sin(phi) * np.cos(theta) - h * np.sin(theta)
z = r * np.sin(phi) * np.sin(theta) + h * np.cos(theta)

fig = plt.figure()
ax = plt.subplot(111, projection='3d')
ax.plot(x, y, z)
plt.show()

I've written this code, that draws a circle, angled at 30 degrees. How do I animate a circle, that stays a circle and just tilts on its center, according to angle "theta" and variable "h"?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

1 Answers1

1

Use animation

import matplotlib.animation as animation

# (...) your code

# Your plot, but keeping the artist result
pltdata,=ax.plot(x, y, z)

def animate(i):
    theta = 0.524 + i*0.02
    x = r * np.cos(phi)
    y = r * np.sin(phi) * np.cos(theta) - h * np.sin(theta)
    z = r * np.sin(phi) * np.sin(theta) + h * np.cos(theta)
    pltdata.set_data(x, y)
    pltdata.set_3d_properties(z)
    return [pltdata]

theAnim = animation.FuncAnimation(fig, animate, frames=314, interval=40, blit=True, repeat=False)
plt.show()

enter image description here

chrslg
  • 9,023
  • 5
  • 17
  • 31