Requires Python 3.6 or greater and if not on Linux or macOS, the wcwidth library, which users can install with:
pip3 install wcwidth
# or
python3 -m pip install wcwidth
See the tables.py file for full usage information.
Complete versions of all of the examples below and more can be found in the test.py file.
Run with: python3 -OO test.py
.
import tables
# Set array
tables.array(array, headerrow=True, headercolumn=True)
Table cells can contain Unicode characters and formatted text with ANSI escape sequences, but not newlines and tabs.
import tables
headerrow = ["Header row/column 1", "Header row 2", "Header row 3", "Header row 4", "Header row 5"]
headercolumn = ["Header column 2", "Header column 3", "Header column 4", "Header column 5"]
# Set array
tables.array(array, headerrow, headercolumn, headerrow=True, headercolumn=True)
Output same as example above.
import tables
# Set array, can be any sequence data type
tables.array(array)
import tables
# Set array
sortdimension = 0 # Column to sort by
array = sorted(array, key=lambda x: x[sortdimension])
tables.array(array)
import tables
def afunction(x):
return x + 1
xmin = -10
xmax = 10
xstep = 0.5
tables.function(xmin, xmax, xstep, afunction, headerrow=True)
import tables
xmin = -10
xmax = 10
xstep = 0.5
afunction = lambda x: x + 1
tables.function(xmin, xmax, xstep, afunction, headerrow=True)
Output same as example above.
import tables
def function1(x):
return 2 * x
def function2(x):
return x ** 2
xmin = -10
xmax = 10
xstep = 0.5
# Function parameter and return value can be any data type, as long as they are the same
functions = [function1, function2]
tables.functions(xmin, xmax, xstep, functions, headerrow=True)
import tables
xmin = -10
xmax = 10
xstep = 0.5
# Function parameter and return value can be any data type, as long as they are the same
functions = [lambda x: 2 * x, lambda x: x ** 2]
tables.functions(xmin, xmax, xstep, functions, headerrow=True)
Output same as example above.
Option: headerrow
Default value: False
Header rows are bolded, centered and have a border.
Option: headercolumn
Default value: False
Header columns are bolded, centered and have a border.
Option: tableborder
Default value: True
Option: cellborder
Default value: False
Option: padding
Default value: 1
Option: alignment
Values:
None
(default)False
(left)True
(right)
Option: title
Default value: None
The title is output at the top of the table. It is word wrapped based on the current width of the terminal. Handles newlines, tabs and Unicode characters.
Option: style
Values:
style_types.ASCII
: ASCIIstyle_types.basic
: Basicstyle_types.light
: Light (default)style_types.heavy
: Heavystyle_types.double
: Doublestyle_types.arc
: Light Arcstyle_types.light_dashed
: Light Dashedstyle_types.heavy_dashed
: Heavy Dashed
Option: check
Default value: True
Check that the width of the table is not greater then the width of the terminal.
Requires Python 3.6 or greater and if not on Linux or macOS, the wcwidth library, which users can install with:
pip3 install wcwidth
# or
python3 -m pip install wcwidth
See the graphs.py file for full usage information.
Complete versions of all of the examples below and more can be found in the test.py file.
Run with: python3 -OO test.py
.
If height
is 0
, it will be set to the current height of the terminal (number of rows times four). If width
is 0
, it will be set to the current width of the terminal (number of columns times two).
import graphs
height = 160
width = 160
xmin = -20
xmax = 20
ymin = -20
ymax = 20
# Set array, can be any sequence data type
graphs.histogram(height, width, xmin, xmax, ymin, ymax, array)
If xmin
and xmax
are both 0
, they will be set to the respective minimum and maximum values of x in the array. If ymin
and ymax
are both 0
, they will be set to the respective minimum and maximum values of y in the resulting histogram.
import graphs
height = 160
width = 160
xmin = -20
xmax = 20
ymin = -20
ymax = 20
# Set array, can be any sequence data type, but must have exactly two columns
graphs.plot(height, width, xmin, xmax, ymin, ymax, array)
If xmin
and xmax
are both 0
, they will be set to the respective minimum and maximum values of x in the array. If ymin
and ymax
are both 0
, they will be set to the respective minimum and maximum values of y in the array.
Use graphs.plots()
to plot multiple arrays, which can be of different sizes.
import graphs
def afunction(x):
return x + 1
height = 160
width = 160
xmin = -20
xmax = 20
ymin = -20
ymax = 20
graphs.function(height, width, xmin, xmax, ymin, ymax, afunction)
import graphs
height = 160
width = 160
xmin = -20
xmax = 20
ymin = -20
ymax = 20
afunction = lambda x: x + 1
graphs.function(height, width, xmin, xmax, ymin, ymax, afunction)
Output same as example above.
import graphs
def function1(x):
return 2 * x
def function2(x):
return x ** 2
height = 160
width = 160
xmin = -20
xmax = 20
ymin = -20
ymax = 20
# Function parameter and return value can be any data type, as long as they are the same
functions = [function1, function2]
graphs.functions(height, width, xmin, xmax, ymin, ymax, functions)
import graphs
height = 160
width = 160
xmin = -20
xmax = 20
ymin = -20
ymax = 20
# Function parameter and return value can be any data type, as long as they are the same
functions = [lambda x: 2 * x, lambda x: x ** 2]
graphs.functions(height, width, xmin, xmax, ymin, ymax, functions)
Output same as example above.
Option: border
Default value: False
Option: axis
Default value: True
Option: axislabel
Default value: True
Requires axis
to be True
.
Option: axistick
Default value: True
Requires axis
to be True
.
Option: axisunitslabel
Default value: True
Requires axis
and axistick
to be True
.
Option: xunits
Values:
units_types.number
: Locale number formatunits_types.scale_none
: Locale number format with full precisionunits_types.scale_SI
: Auto-scale to the SI standardunits_types.scale_IEC
: Auto-scale to the IEC standardunits_types.scale_IEC_I
: Auto-scale to the IEC standardunits_types.fracts
: Locale number format, but convert fractions and mathematical constants to Unicode characters (default)units_types.percent
: Percentage formatunits_types.date
: Locale date formatunits_types.time
: Locale time formatunits_types.monetary
: Locale monetary/currency format
Formats 2-5 are similar to the respective --to
options with the numfmt command from GNU Coreutils, but with more precision.
Option: yunits
Values: Same as above.
Option: type
Values:
The Braille type has the highest resolution of 2Γ4 pixels per character, while the block type uses 2Γ2. This option is only used for plots and graphs. Histograms use 1Γ8 pixels per character.
Option: mark
Values:
The dot mark type uses a single pixel per mark, the plus uses five pixels and the square uses eight pixels. This option is only used for plots and graphs.
Option: title
Default value: None
The title is output at the top of the graph. It is word wrapped based on the current width of the terminal. Handles newlines, tabs and Unicode characters.
Option: style
Values:
style_types.ASCII
: ASCIIstyle_types.basic
: Basicstyle_types.light
: Light (default)style_types.heavy
: Heavystyle_types.double
: Doublestyle_types.arc
: Light Arcstyle_types.light_dashed
: Light Dashedstyle_types.heavy_dashed
: Heavy Dashed
Option: color
Values:
color_types.default
: System defaultcolor_types.black
: Blackcolor_types.red
: Red (default)color_types.green
: Greencolor_types.yellow
: Yellowcolor_types.blue
: Bluecolor_types.magenta
: Magentacolor_types.cyan
: Cyancolor_types.white
: Whitecolor_types.gray
: Graycolor_types.bright_red
: Bright Redcolor_types.bright_green
: Bright Greencolor_types.bright_yellow
: Bright Yellowcolor_types.bright_blue
: Bright Bluecolor_types.bright_magenta
: Bright Magentacolor_types.bright_cyan
: Bright Cyancolor_types.bright_white
: Bright White
See here for examples of the colors.
This option is only used when plotting a single array and when graphing a single function. When plotting multiple arrays or graphing multiple functions, colors 2 - 16 are used inorder. The system default color is used where the plots cross.
Option: check
Default value: True
Check that the width and height of the graph are not greater then the respective width and height of the terminal.