3D plots in Kivy

33 views
Skip to first unread message

Iacopo Sagliano

unread,
Aug 5, 2025, 5:55:20 AMAug 5
to Kivy users support
Hello,

I’m working on a Kivy-based project and looking for a working way to display interactive 3D plots inside my app. I've read 3D plots are not natively supported by Kivy. My goals are:
- Plot interactivity (rotation, zoom, hover)
- Cross-platform support (desktop and Android preferred)

Any guidance, suggestions, or maintained forks would be greatly appreciated!

Thanks,
Iacopo

Kenechukwu Akubue

unread,
Aug 5, 2025, 9:45:22 AMAug 5
to kivy-...@googlegroups.com
You might want to check this out https://github.com/mp-007/kivy_matplotlib_widget

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/kivy-users/99268962-30f5-4275-8300-b51e0928c897n%40googlegroups.com.

berk berk

unread,
Aug 11, 2025, 12:02:01 PMAug 11
to Kivy users support
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()

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

Moses David Kapila

unread,
Aug 12, 2025, 10:14:28 AMAug 12
to kivy-...@googlegroups.com
Hello,

You’re right that Kivy doesn’t natively support interactive 3D plots out of the box. However, there are some ways you can approach this:

1. Use OpenGL or Kivy’s kivy3 module:

The kivy3 project adds some 3D capabilities to Kivy using OpenGL, though it’s somewhat basic and more focused on 3D models than plots. You could potentially build custom 3D visualizations with it.



2. Embed other libraries using kivy.garden or kivy.uix.widget with OpenGL context:

Libraries like PyOpenGL can be used for custom 3D rendering, but this requires significant effort to build interactive plots.



3. Use external 3D plotting libraries and embed via WebView:

Tools like Plotly or ipywidgets allow interactive 3D plotting inside a web browser. You can embed a WebView widget inside Kivy (e.g., kivy-webview) to show such plots. This approach supports rotation, zoom, hover, and is cross-platform if WebView is supported on your target devices.



4. Consider other frameworks for complex 3D plotting:

If your app can afford a heavier dependency, frameworks like PyQt or PySide combined with matplotlib’s 3D plotting or vtk might be easier for 3D plotting — but they won’t run on Android without extra work.

Reply all
Reply to author
Forward
0 new messages