Using python and matplotlib on android
Asked Answered
T

13

35

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)
Tunable answered 21/8, 2013 at 9:4 Comment(1)
There is a similar topic: #13793658Shetler
S
6

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 ;)

Swint answered 30/8, 2013 at 5:57 Comment(0)
S
5

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

Pydroid for Python 2.7

Pydroid 3 for Python 3.6

Sennight answered 12/11, 2017 at 18:20 Comment(0)
G
1

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).

Gillan answered 6/3, 2015 at 19:57 Comment(0)
O
1

Upon searching numpy android on Google, I found a very nice library. I guess it might be helpful.

The above link no longer works. Please find more information regarding the library here.

Oof answered 5/6, 2017 at 10:50 Comment(1)
Link seems dead.Robison
Q
1

Yes, it can be done, even without root. You need the termux app, it basically is a terminal emulator with a full Linux environment and via apt install python, for example, you can install python.

The main webpage is here, and it is of course available via the standard market. (The termux wiki is a helpful place.)

Qualification answered 16/9, 2017 at 15:3 Comment(0)
G
0

ever heard of qpython? http://qpython.com/ i personally never used it, but my colleague were quite handy with it so you may want to look at that

Gudrin answered 21/8, 2013 at 11:31 Comment(3)
I don't think it supports matplotlib does it?Tunable
maybe this? qpython.org/question/62/… or just check the FAQGudrin
The link is dead, archived version hereBrotherhood
J
0

I've read somewhere that scipy and matplotlib cannot be compiled for android, someone did it for numpy though

https://code.google.com/p/android-scripting/issues/detail?id=260

Juan answered 27/8, 2013 at 3:22 Comment(0)
A
0

You could set up a cheap server (Raspberry Pi?) and create an ssh connection to it to access full python functionality through a vnc viewer android app or the shell

Atman answered 26/11, 2014 at 4:11 Comment(0)
P
0

You can try MathSys. It's a wrapper around Python, and it has matplotlib inside.

Unfortunately, MathSys is rather convoluted, and it's an alpha version. Apparently, nobody is working on a beta version. You'll want to write any complicated code in an external file. import works fine in MathSys.

Ptolemaic answered 21/5, 2015 at 3:59 Comment(0)
Q
0

Here is the code, this works after installing GNURoot Debian as you said. Just a detail : my graph is exported directly in a .png file :

from pylab import *
import matplotlib.pyplot as plt
plt.switch_backend('agg')
x = linspace(-5, 5, 100)
y = sin(x)
plot(x, y)
out_png = 'out_file.png'
plt.savefig(out_png, dpi=150)
Quartus answered 18/10, 2017 at 21:17 Comment(0)
K
0

There is a lot of incorrect information in this thread! I first tried Termux, using the information from this thread: How do I install Jupyter notebook on an Android device? but could not get Matplotlib downloaded for the life of me. The error messages suggested I needed to install wheel, which I did, but the install crash was only postponed. I am not saying it is not possible to install Matplotlib from Termux on a Galaxy Tab A, but I cannot do it. On the other hand, downloading Pyroid3 was straightforward, as was installing numpy, scipy and matplotlib. So that's my recommendation, based on success in doing so.

Kumquat answered 9/12, 2020 at 14:14 Comment(0)
S
0

I just got this running for myself and these are the steps I used:

  1. install termux (from the Play Store or FDroid)
  2. install python in termux:
pkg install python
  1. install matplotlib
  2. install a graphical environment for matplotlib (I installed tkinter):
pkg install python-tkinter
  1. install an X server (I used XServer XSDL)
  2. use this initialization sequence in your python:
import os
from time import sleep
os.environ["MPLBACKEND"] = "TkAgg"
os.environ["DISPLAY"] = ":0.0"
print('Loading X server...')
os.system("am start --user 0 -n x.org.server/.RunFromOtherApp 2>/dev/null")
os.environ["DISPLAY"] = ":0.0"
sleep(8) # give the X server an opportunity to start
print('Done')
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
plt.show()

There's probably a better way to detect whether the X server is already running so you don't have to launch it every time, but I haven't figured out how to do that yet.

Semidome answered 21/2, 2022 at 19:53 Comment(0)
I
-2

Use the linux shell, I have it git python and pip installed on my phone. I used gnuroot in the play store.. You can apt-get install python pip from there

Immigrate answered 29/10, 2015 at 23:15 Comment(2)
Very unclear answer. You could edit it and at least use formatting to clearly differentiate between commands and plain words (and while there maybe clean the grammer a bit?): stackoverflow.com/help/how-to-answerRitchey
Use the linux shell? I think on Linux it's already running but not on AndroidElizbeth

© 2022 - 2024 — McMap. All rights reserved.