With Octave I am able to plot arrays to the terminal, for example, plotting an array with values for the function x^2
gives this output in my terminal:
See also: asciichart (implemented in Node.js, Python, Java, Go and Haskell)
As @Benjamin Barenblat pointed out, there is currently no way using matplotlib. If you really want to use a pure python library, you may check ASCII Plotter. However, as I commented above, I would use gnuplot as suggested e.g. in this question.
To use gnuplot directly from python you could either use Gnuplot.py (I haven't tested this yet) or use gnuplot with the scripting interface. Latter can be realised (as suggested here) like:
import numpy as np
x=np.linspace(0,2*np.pi,10)
y=np.sin(x)
import subprocess
gnuplot = subprocess.Popen(["/usr/bin/gnuplot"],
stdin=subprocess.PIPE)
gnuplot.stdin.write("set term dumb 79 25\n")
gnuplot.stdin.write("plot '-' using 1:2 title 'Line1' with linespoints \n")
for i,j in zip(x,y):
gnuplot.stdin.write("%f %f\n" % (i,j))
gnuplot.stdin.write("e\n")
gnuplot.stdin.flush()
This gives a plot like
1 ++--------+---A******---------+--------+---------+---------+--------++
+ + ** +A* + + + Line1 **A*** +
0.8 ++ ** * ++
| ** ** |
0.6 ++ A * ++
| * * |
0.4 ++ * ++
| ** A |
0.2 ++* * ++
|* * |
0 A+ * A ++
| * * |
-0.2 ++ * * ++
| A* ** |
-0.4 ++ * * ++
| ** * |
-0.6 ++ * A ++
| * ** |
-0.8 ++ ** ++
+ + + + + A****** ** + +
-1 ++--------+---------+---------+--------+--------A+---------+--------++
0 1 2 3 4 5 6 7
Some styling options can be found e.g. here.
Check the package plotext which allows to plot data directly on terminal using python3. It is very intuitive as its use is very similar to the matplotlib package.
Here is a basic example:
You can install it with the following command:
sudo -H pip install plotext
As for matplotlib, the main functions are scatter (for single points), plot (for points joined by lines) and show (to actually print the plot on terminal). It is easy to specify the plot dimensions, the point and line styles and whatever to show the axes, number ticks and final equations, which are used to convert the plotted coordinates to the original real values.
Here is the code to produce the plot shown above:
import plotext.plot as plx
import numpy as np
l=3000
x=np.arange(0, l)
y=np.sin(4*np.pi/l*np.array(x))*np.exp(-0.5*np.pi/l*x)
plx.scatter(x, y, rows = 17, cols = 70)
plx.show(clear = 0)
The option clear=True
inside show
is used to clear the terminal before plotting: this is useful, for example, when plotting a continuous flow of data.
An example of plotting a continuous data flow is shown here:
The package description provides more information how to customize the plot. The package has been tested on Ubuntu 16 where it works perfectly. Possible future developments (upon request) could involve extension to python2 and to other graphical interfaces (e.g. jupiter). Please let me know if you have any issues using it. Thanks.
I hope this answers your problem.