plotext plots data directly on terminal
Project description
The package plotext allows to plot data directly on terminal.
Basic Example
You can use plotext to plot directly on terminal, as you would normally with matplotlib. Here is a basic example on how to use it:
import plotext.plot as plx
plx.scatter(x, y)
plx.show()
where x and y are the lists for the of points coordinates; optionally, a single y list could be provided. Alternatively, you could plot data points with lines connecting them using the plot function instead of the scatter one. Multiple data set could also be plotted using consecutive scatter or plot functions. Here is an output example:
Each data point is represented by a character (in this case a •).
Installation
To install the latest version of the plotext package use the following command:
sudo -H pip install plotext
Parameters
You can personalize the plots in different ways using the scatter and plot function parameters. Here they are:
-
cols It sets the number of columns of the plot. Only integers are allowed. By default, it is set to the highest value allowed by the the terminal size. Alternatively you could set the number of rows using
set_cols(cols)after the scatter function. -
rows It sets the number of rows of the plot. Only integers are allowed. By default, it is set to the highest value allowed by the the terminal size. Alternatively you could set the number of columns using
set_rows(rows)after thescatterorplotfunction. -
force_size The plot dimensions are limited by the terminal size, when
force_sizeis False and are allowed to be bigger otherwise. The default value isFalse. Alternatively you could setforce_sizeusingset_force_size(force_size)after thescatterorplotfunction but beforeset_cols(cols)andset_rows(rows). -
xlim It sets the minimum and maximum limits of the plot in the
xaxis. It requires a list of two numbers, where the first sets the left (minimum) limit and the second the right (maximum) limit. If one or both values are not provided, they are calculated automatically. Alternatively you could useset_xlim(xlim)after thescatterorplotfunction. -
ylim It sets the minimum and maximum limits of the plot in the
yaxis. It requires a list of two numbers, where the first sets the lower (minimum) limit and the second the upper (maximum) limit. If one or both values are not provided, they are calculated automatically. Alternatively you could useset_ylim(ylim)after thescatterorplotfunction. -
point When
True, the plot shows the scatter data points. The default value isTrue. -
point_marker It sets the marker used to identify each data point on the plot. Only single characters are allowed (eg:
'*'). The default value is'•'. -
point_color It sets the color used for the point marker. Use
get_colors()to find the available color codes. The default value is'norm'. -
line When True, the plot shows the lines between each data points. The default value is
False. -
line_marker It sets the marker used to identify the lines between data points. Only single characters are allowed (eg:
'*'). The default value is'•'. -
line_color It sets the color used for the line marker. Use
get_colors()to find the available color codes. The default value is'norm'. -
background It sets the plot background color. Use
get_colors()to find the available color codes. The default value is'norm'. Alternatively you could set the background color usingset_background(background)after thescatterorplotfunction. -
axes When True, the
xandyaxes are added to the plot. A list of two Boolean will set thexandyaxes separately (eg:axes = [True, False]). The default value isTrue. -
axes_color It sets the color of the axes, ticks and equations, when present. Use
get_colors()to find the available color codes. The default value is'norm'. Alternatively you could set the axes color usingset_axes_color(axes_color)after the scatter function. -
ticks When
True, thexandyticks are added to the respective axes (even when absent). A list of two Boolean will set thexandyticks separately (eg:ticks = [True, False]). The default value isTrue. -
spacing It sets the spacing between the
xandyticks. When a list of two numbers is given, the spacing of thexandyticks are set separately (eg:spacing = [5, 8]). Only positive integers are allowed. The default value is[10, 5]. Alternatively you could useset_spacing(spacing)after thescatterorplotfunction. -
equations When
True, the equations - needed to to find the realxandyvalues from the plot coordinates - are added at the end of the plot. The default value isFalse. -
decimals It sets the number of decimal points shown in the equations. Only positive integers are allowed. The default value is
2. Alternatively you could set the decimal points usingset_decimals(decimals)after thescatterorplotfunction.
Save Plot
You can save your plot, as a text file, using plx.savefig(path) where path is the file address where the data will be written. Note that (for now), this function doesn't preserve the plot colors.
Streaming Data
The following functions are useful for example when continuously plotting a stream of data.
In order to clear the plot canvas use:
plx.clear_plot()
and to clear the terminal use:
plx.clear_terminal()
A common problem when plotting streaming data is the screen flickering. In order to remove or reduce this problem use:
plx.sleep(time)
which adds a sleeping time to the computation. An input of, for example, 0.01 would add approximately 0.01 secs to the computation. The time parameters will depend on your processor speed and it needs some manual tweaking.
Here is an example of plotting a continuous stream of data:
Equations
As previously written, you could add two equations at the end of the plot to transform the column and row coordinatesdisplayeddisplayed into real x and y coordinates. Here is an example of a plot with equations at the end:
The errors in the equations are due to the fact that the pixel size reduces the resolution of the data displayed.
Alternatively you could access the functions plx.get_x_from_col(col) and plx.get_y_from_row(row) to make python do the transformation from your chosen column and row to real, respectively, x and y coordinates.
Colors
You can access the function plx.get_colors() in order to find the available full ground and background color codes. Here is the output for simplicity:
Test
You can run a simple initial test of your newly installed package, to check that plotext works well in your machine. Just use plx.run_test()
Version
In order to check the installed version of the package use the command plx.get_version()
Other Documentation
The full documentation of any of the functions shown above could be accessed using commands like these:
print(plx.scatter.__doc__)
print(plx.plot.__doc__)
print(plx.show.__doc__)
Main Updates:
plotextnow works also in Windows comand line (CMD) with colorsplotextnow works also using Python IDLE3 but with no colors and no adaptive dimensions- new color codes with background codes added
force_sizeoption addedsavefigfunction addedget_versionfunction addedrun_testfunction added- no need for
numpyortimepackages - the code has been updated and it is more legible
- the documentation has been updated
equationsoptions now is set by default toFalse- When
thickisFalse, the axes non numerical thicks are also removed - Removed get functions for plot parameters
Creator
- Author: Savino Piccolomo
- e-mail: piccolomo@gmail.com
Contributors
- Dominik Wetzel, Schmetzler for the Windows support
- Dominik Wetzel for force_size idea
- Kexul, Madrian for their inputs regarding plotting multiple lines
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plotext-1.0.11.tar.gz.
File metadata
- Download URL: plotext-1.0.11.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46a68ab7cbd08ca38ab3f4d697127528623cb1eac1823f133d6b8ab55fc0ec2e
|
|
| MD5 |
5adc31eb0baf6430210e6df810bbebca
|
|
| BLAKE2b-256 |
ea1fc90e0534d79b0c3bef2419aec494ad4c525e31ed76297e6692f1e586886f
|
File details
Details for the file plotext-1.0.11-py3-none-any.whl.
File metadata
- Download URL: plotext-1.0.11-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1edb6d9f5cb37762797c9ff7df70e810c68e0e0eb90455bdd9e06221882e5a9c
|
|
| MD5 |
3098fb4a8ff58ae18d1dd86b01a828da
|
|
| BLAKE2b-256 |
19bb98345d7b4c7423e29f9699621645d9a8e51f73ad15efb31dbf7eaaff141b
|