look at this sample:
the method is :
#1st create a 3d rotating graph as a gif.
#2nd use kivy Image()
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
from
kivy.app import App
from kivy.uix.image import Image
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.clock import Clock
import os
class MyLayout(BoxLayout):
def __init__(self, **kwargs):
super().__init__(orientation='vertical', **kwargs)
self.image = Image(source='', anim_delay=0.05)
self.add_widget(self.image)
btn = Button(text='Display')
btn.bind(on_press=self.generate_and_show_gif)
self.add_widget(btn)
def generate_and_show_gif(self, instance):
self.create_3d_animation(path='animated')
Clock.schedule_once(lambda dt: self.update_image_source('animated.gif'), 0.5)
def update_image_source(self, filepath):
self.image.source = ''
self.image.source = filepath
self.image.reload()
def create_3d_animation(self, path='animated', frame=50, interval=50, fps=20):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# sample of 3d graph
t = np.linspace(0, 4 * np.pi, 100)
x = np.sin(t)
y = np.cos(t)
z = t
ax.plot3D(x, y, z, 'blue')
def animate(i):
ax.view_init(elev=30., azim=i * (360 / frame))
return fig,
ani = animation.FuncAnimation(fig, animate, frames=frame, interval=interval, blit=False)
ani.save(f'{path}.gif', writer='pillow', fps=fps)
plt.close(fig) #close
class MyApp(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
MyApp().run()

5 Ağustos 2025 Salı tarihinde saat 16:45:22 UTC+3 itibarıyla
keng...@gmail.com şunları yazdı: