I have recently learned a bit of matplotlib and would like to use it within kivy. I have read a little documentation on the garden here and there but don't really understand it. I have installed kivy garden and matplotlib but don't know how to proceed from here. I simply want to add a already completed matplotlib graph into kivy. I would appreciate a step by step simplified set of instructions of how to get what I already coded into kivy and get it to display. Thanks
-
2I did read it. What is the problem? Title is relevant, I outlined the problem and added tags.user8216532– user82165322017-07-04 14:17:02 +00:00Commented Jul 4, 2017 at 14:17
-
1Stackoverflow is more targeted to specific questions like "why does this line produce an error" or "how can I turn the background of a kivy widget blue". You can save a png from matplotlib and display it with an image from kivy.syntonym– syntonym2017-07-04 14:58:15 +00:00Commented Jul 4, 2017 at 14:58
-
Oh I see, this was my second post here so I didn't know. Guess I'll have to look into animating the graph instead then.user8216532– user82165322017-07-04 15:01:23 +00:00Commented Jul 4, 2017 at 15:01
-
Are there convenient solutions for interactive figures in Kivy after 4 years? Related question: stackoverflow.com/questions/68345620/…Martin– Martin2021-07-13 12:17:42 +00:00Commented Jul 13, 2021 at 12:17
Add a comment
|
1 Answer
Here is the simplest example possible for kivy-garden matplotlib and kivy. If you would like to do more advanced things, check out their examples: https://github.com/kivy-garden/garden.matplotlib/tree/master/examples I think it should be enough to get you started with your plot.
Below I am adding it to a BoxLayout, you can add more widgets to this BoxLayout or add this BoxLayout somewhere else.
python code example.py:
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import matplotlib.pyplot as plt
plt.plot([1, 23, 2, 4])
plt.ylabel('some numbers')
class MyApp(App):
def build(self):
box = BoxLayout()
box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
return box
MyApp().run()
3 Comments
Neda
But the problem is that it is not an interactive figure!!! it's just a picture with no activity to zoom or cursor!
PalimPalim
matplotlib is not the right library for interactive figures IMHO. I would suggest to look into bokeh or plotly for a start. (not sure why so many !)
Neda
I wished to use an interactive figure in raspberry pi and touch screen do you still believe bokeh and plotly are better in touch screen and raspberry pi?
