Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using python and matplotlib on android

Is there a way to set up python 2.7.x + matplotlib on an android tablet so that you can run simple standard python code? I would like to be able to run the same scripts I run on my Linux desktop. This is just for my own use and I don't need to distribute the code to anyone else.

As a concrete example, is it possible to run this script?

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
like image 282
marshall Avatar asked Aug 21 '13 09:08

marshall


People also ask

Can I use Python in Android?

Python can run on Android through various apps from the play store library. This tutorial will explain how to run python on Android using Pydroid 3 – IDE for Python 3 application. Features : Offline Python 3.7 interpreter: no Internet is required to run Python programs.

Can you use Python in Android Studio?

Chaquopy is a plugin for Android Studio's Gradle-based build system. Chaquopy enables you to freely intermix Java and Python in your app, using whichever language is best for your needs: With the Python API , you can write an app partly or entirely in Python.

How do I open a Python file on Android?

If you want to run Python on mobile, one of the easiest options is simply to download an IDE on your chosen platform. There is no need to download a separate interpreter, you can simply download the app and start typing and running your Python code.

Can you use Matplotlib in Python?

Matplotlib is a cross-platform, data visualization and graphical plotting library for Python and its numerical extension NumPy. As such, it offers a viable open source alternative to MATLAB. Developers can also use matplotlib's APIs (Application Programming Interfaces) to embed plots in GUI applications.


3 Answers

Is it easy, no.

Can it be done? Yes. I believe a skilled Python / Android developer could do it in 2 to 8 hours of effort.. It's a rare and complex request.

Why do I think it can be done? This sample: http://matplotlib.org/examples/pylab_examples/webapp_demo.html

Using a different library, and not abstracted for data without live hardware, this sample shows me that SL4A can do web-based graphics: http://www.smartphonedaq.com/android-python-ecg.page

Now, if you were talking native GUI graphics in Android - then I'm focused way too much on the web methods of publishing with SL4A ;)

like image 191
RoundSparrow hilltx Avatar answered Sep 28 '22 10:09

RoundSparrow hilltx


Pydroid is great for Matplotlib on Android, supports Numpy and many other libraries:

Pydroid for Python 2.7

Pydroid 3 for Python 3.6

like image 35
Sandor Rado Avatar answered Sep 28 '22 09:09

Sandor Rado


There is an app called Gnuroot that allows you to run a kind-of chroot (proot), where you can install a linux distro such as debian, archlinux...
For the gui, there is the option to run a vncserver for an X server and use some android vnc client app to show the screen.

I use the non-gui version of gnuroot and it works well. I now have a command line debian wheezy on android lollipop arm. One minor thing i miss, is armhf (hardware floating point which my nexus7's processor can do) support instead of armel (software floating point).

like image 34
yoghurt Avatar answered Sep 28 '22 09:09

yoghurt