Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add this example: How to use in kv file #65

Open
escallonia opened this issue Apr 23, 2020 · 0 comments
Open

Please add this example: How to use in kv file #65

escallonia opened this issue Apr 23, 2020 · 0 comments

Comments

@escallonia
Copy link

escallonia commented Apr 23, 2020

This example shows how to extend FigureCanvasKivyAgg for use in a kv file.

extend4kv.py:

#!/usr/bin/env python3                                                                
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg                
from kivy.app import App                                                              
import matplotlib.pyplot as plt                                                                                                                                             

plt.plot([1, 23, 2, 4])                                                               
plt.ylabel('some numbers')                                                                                                                                                  

# A class in which __init__ has no positional parameters, so it can be used in a kv file:
class MyFigure(FigureCanvasKivyAgg):                                                      
    def __init__(self, **kwargs): 
        super().__init__(plt.gcf(), **kwargs)    

class Extend4Kv(App):
    pass

Extend4Kv().run()

Now use in the file extend4kv.kv:

# kv file
MyFigure:
@escallonia escallonia changed the title Please add this example: How use in kv file Please add this example: How to use in kv file Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant