8000 Added matplotlib testapp · sfoerster/python-for-android@416b750 · GitHub
[go: up one dir, main page]

Skip to content

Commit 416b750

Browse files
committed
Added matplotlib testapp
1 parent 25f05fa commit 416b750

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
from distutils.core import setup
3+
from setuptools import find_packages
4+
5+
options = {'apk': {'requirements': 'sdl2,python3,matplotlib,pyparsing,cycler,python-dateutil,numpy,kiwisolver,kivy',
6+
'blacklist-requirements': 'openssl,sqlite3',
7+
'android-api': 27,
8+
'ndk-api': 21,
9+
'dist-name': 'matplotlib_testapp',
10+
'ndk-version': '10.3.2',
11+
'permission': 'VIBRATE',
12+
}}
13+
14+
package_data = {'': ['*.py',
15+
'*.png']
16+
}
17+
18+
packages = find_packages()
19+
print('packages are', packages)
20+
21+
setup(
22+
name='testapp_matplotlib',
23+
version='0.1',
24+
description='p4a setup.py test',
25+
author='Alexander Taylor',
26+
author_email='alexanderjohntaylor@gmail.com',
27+
packages=find_packages(),
28+
options=options,
29+
package_data={'testapp_matplotlib': ['*.py', '*.png']}
30+
)

testapps/testapp_matplotlib/main.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
print('importing numpy')
2+
import numpy as np
3+
print('imported numpy')
4+
5+
print('importing matplotlib')
6+
7+
import matplotlib
8+
print('imported matplotlib')
9+
10+
print('importing pyplot')
11+
12+
from matplotlib import pyplot as plt
13+
14+
print('imported pyplot')
15+
16+
fig, ax = plt.subplots()
17+
18+
print('created fig and ax')
19+
20+
ax.plot(np.random.random(50))
21+
22+
print('plotted something')
23+
24+
ax.set_xlabel('test label')
25+
26+
print('set a label')
27+
28+
fig.set_size_inches((5, 4))
29+
fig.savefig('test.png')
30+
31+
print('saved fig')
32+
33+
from kivy.app import App
34+
from kivy.uix.image import Image
35+
from kivy.lang import Builder
36+
37+
class MatplotlibApp(App):
38+
def build(self):
39+
root = Builder.load_string("""
40+
BoxLayout:
41+
orientation: 'vertical'
42+
Image:
43+
id: the_image
44+
source: 'test.png'
45+
allow_stretch: True
46+
Button:
47+
size_hint_y: None
48+
height: dp(40)
49+
text: 'new plot'
50+
on_release: app.generate_new_plot()
51+
""")
52+
return root
53+
54+
def generate_new_plot(self):
55+
fig, ax = plt.subplots()
56+
ax.set_xlabel('test xlabel')
57+
ax.set_ylabel('test ylabel')
58+
ax.plot(np.random.random(50))
59+
ax.plot(np.sin(np.linspace(0, 3*np.pi, 30)))
60+
61+
ax.legend(['random numbers', 'sin'])
62+
63+
fig.set_size_inches((5, 4))
64+
fig.tight_layout()
65+
66+
fig.savefig('test.png', dpi=150)
67+
68+
self.root.ids.the_image.reload()
69+
70+
71+
72+
73+
MatplotlibApp().run()
74+
runTouchApp(Image(source='test.png', allow_stretch=True))

0 commit comments

Comments
 (0)
0