2023-03-13 22:29:43 +08:00
## Table of Contents
* [Tables ](#tables )
* [Usage ](#usage )
* [Options ](#options )
* [Graphs/Plots ](#graphsplots )
* [Usage ](#usage-1 )
* [Options ](#options-1 )
2022-02-01 23:20:23 +08:00
## Tables
### Usage
2023-05-11 22:03:53 +08:00
Requires Python 3.6 or greater and the [wcwidth library ](https://pypi.org/project/wcwidth/ ), which users can install with:
```bash
pip3 install wcwidth
# or
python3 -m pip install wcwidth
```
See the [tables.py ](tables.py ) file for full usage information.
2022-02-01 23:20:23 +08:00
Complete versions of all of the examples below and more can be found in the [test.py ](test.py ) file.
Run with: `python3 test.py` .
2022-07-14 16:33:38 +08:00
#### Output str array as table
2022-02-01 23:20:23 +08:00
```py
import tables
# Set array
2022-07-14 16:33:38 +08:00
tables.array(array, headerrow=True, headercolumn=True)
2022-02-01 23:20:23 +08:00
```
Table cells can contain [Unicode characters ](https://en.wikipedia.org/wiki/List_of_Unicode_characters ), but not newlines and tabs.

#### Output array as table with separate header row and column
```py
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.
#### Output array as table
```py
import tables
2022-07-14 16:33:38 +08:00
# Set array, can be any sequence data type
2022-02-01 23:20:23 +08:00
2022-07-14 16:33:38 +08:00
tables.array(array)
2022-02-01 23:20:23 +08:00
```

#### Output sorted array as table
```py
import tables
# Set array
sortdimension = 0 # Column to sort by
array = sorted(array, key=lambda x: x[sortdimension])
2022-07-14 16:33:38 +08:00
tables.array(array)
2022-02-01 23:20:23 +08:00
```

#### Output single function as table
```py
import tables
def afunction(x):
return x + 1
xmin = -10
xmax = 10
2023-03-10 21:15:01 +08:00
xstep = 0.5
2022-02-01 23:20:23 +08:00
2023-03-10 21:15:01 +08:00
tables.function(xmin, xmax, xstep, afunction, headerrow=True)
2022-02-01 23:20:23 +08:00
```

2022-07-14 16:33:38 +08:00
#### Output lambda function as table
```py
import tables
xmin = -10
xmax = 10
2023-03-10 21:15:01 +08:00
xstep = 0.5
2022-07-14 16:33:38 +08:00
afunction = lambda x: x + 1
2023-03-10 21:15:01 +08:00
tables.function(xmin, xmax, xstep, afunction, headerrow=True)
2022-07-14 16:33:38 +08:00
```
Output same as example above.
2022-02-01 23:20:23 +08:00
#### Output multiple functions as table
```py
import tables
def function1(x):
return 2 * x
def function2(x):
return x ** 2
xmin = -10
xmax = 10
2023-03-10 21:15:01 +08:00
xstep = 0.5
2022-02-01 23:20:23 +08:00
# Function parameter and return value can be any data type, as long as they are the same
functions = [function1, function2]
2023-03-10 21:15:01 +08:00
tables.functions(xmin, xmax, xstep, functions, headerrow=True)
2022-02-01 23:20:23 +08:00
```

2022-07-14 16:33:38 +08:00
#### Output multiple lambda functions as table
```py
import tables
xmin = -10
xmax = 10
2023-03-10 21:15:01 +08:00
xstep = 0.5
2022-07-14 16:33:38 +08:00
# 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]
2023-03-10 21:15:01 +08:00
tables.functions(xmin, xmax, xstep, functions, headerrow=True)
2022-07-14 16:33:38 +08:00
```
Output same as example above.
2022-02-01 23:20:23 +08:00
### Options
#### Header row
Option: `headerrow` \
Default value: `False`
Header rows are bolded, centered and have a border.
#### Header column
Option: `headercolumn` \
Default value: `False`
Header columns are bolded, centered and have a border.
#### Table border
Option: `tableborder` \
2023-03-13 22:29:43 +08:00
Default value: `True`
2022-02-01 23:20:23 +08:00
#### Cell border
Option: `cellborder` \
Default value: `False`
#### Cell padding
Option: `padding` \
Default value: `1`
#### Alignment
Option: `alignment` \
Values:
2023-03-10 21:15:01 +08:00
* `None` (default)
* `False` (left)
2022-02-01 23:20:23 +08:00
* `True` (right)
#### Title
Option: `title` \
Default value: `None`
2023-03-13 22:29:43 +08:00
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 ](https://en.wikipedia.org/wiki/List_of_Unicode_characters ).
2022-02-01 23:20:23 +08:00
#### Border style
Option: `style` \
Values:
2023-03-10 21:15:01 +08:00
0. `style_types.ASCII` : ASCII
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
1. `style_types.basic` : Basic
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
2. `style_types.light` : Light (default)
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
3. `style_types.heavy` : Heavy
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
4. `style_types.double` : Double
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
5. `style_types.light_dashed` : Light Dashed
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
6. `style_types.heavy_dashed` : Heavy Dashed
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
#### Check size
Option: `check` \
Default value: `True`
Check that the width of the table is not greater then the width of the terminal.
2022-02-01 23:20:23 +08:00
## Graphs/Plots
### Usage
2023-05-11 22:03:53 +08:00
Requires Python 3.6 or greater and the [wcwidth library ](https://pypi.org/project/wcwidth/ ), which users can install with:
```bash
pip3 install wcwidth
# or
python3 -m pip install wcwidth
```
See the [graphs.py ](graphs.py ) file for full usage information.
2022-02-01 23:20:23 +08:00
Complete versions of all of the examples below and more can be found in the [test.py ](test.py ) file.
Run with: `python3 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).
2022-07-14 16:33:38 +08:00
#### Output single array as plot
2022-02-01 23:20:23 +08:00
```py
import graphs
height = 160
width = 160
xmin = -20
xmax = 20
ymin = -20
ymax = 20
2022-07-14 16:33:38 +08:00
# Set array, can be any sequence data type, but must have exactly two columns
2022-02-01 23:20:23 +08:00
graphs.array(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.

2022-07-14 16:33:38 +08:00
Use `graphs.arrays()` to plot multiple arrays, which can be of different sizes.
2022-02-01 23:20:23 +08:00
#### Output single function as graph
```py
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)
```

2022-07-14 16:33:38 +08:00
#### Output lambda function as graph
```py
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.
2022-02-01 23:20:23 +08:00
#### Output multiple functions as graph
```py
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)
```

2022-07-14 16:33:38 +08:00
#### Output multiple lambda functions as graph
```py
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.
2022-02-01 23:20:23 +08:00
### Options
2023-03-13 22:29:43 +08:00
#### Border
2022-02-01 23:20:23 +08:00
Option: `border` \
Default value: `False`
2023-03-13 22:29:43 +08:00
#### Axis
Option: `axis` \
Default value: `True`
2022-02-01 23:20:23 +08:00
#### Axis labels
Option: `axislabel` \
2023-03-13 22:29:43 +08:00
Default value: `True`
Requires `axis` to be `True` .
2022-02-01 23:20:23 +08:00
2023-05-11 22:03:53 +08:00
#### Axis tick marks
2023-03-13 22:29:43 +08:00
Option: `axistick` \
Default value: `True`
2023-05-11 22:03:53 +08:00
Requires `axis` to be `True` .
2022-02-01 23:20:23 +08:00
#### Axis units labels
Option: `axisunitslabel` \
2023-03-13 22:29:43 +08:00
Default value: `True`
2022-02-01 23:20:23 +08:00
2023-05-11 22:03:53 +08:00
Requires `axis` and `axistick` to be `True` .
#### X-axis units format
Option: `xunits` \
Values:
1. `units_types.number` : Locale number format
2. `units_types.scale_none` : Locale number format with full precision
3. `units_types.scale_SI` : Auto-scale to the SI standard
4. `units_types.scale_IEC` : Auto-scale to the IEC standard
5. `units_types.scale_IEC_I` : Auto-scale to the IEC standard
6. `units_types.fracts` : Locale number format, but convert fractions and mathematical constants to Unicode characters (default)
7. `units_types.percent` : Percentage format
8. `units_types.date` : Locale date format
9. `units_types.time` : Locale time format
10. `units_types.monetary` : Locale monetary/currency format
Formats 2-5 are similar to the respective `--to` options with the [numfmt ](https://www.gnu.org/software/coreutils/manual/html_node/numfmt-invocation.html ) command from GNU Coreutils, but with [more precision ](https://github.com/tdulcet/Numbers-Tool#comparison-of---to-option ).
#### Y-axis units format
Option: `yunits` \
Values: Same as above.
2022-02-01 23:20:23 +08:00
#### Title
Option: `title` \
Default value: `None`
2023-03-13 22:29:43 +08:00
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 ](https://en.wikipedia.org/wiki/List_of_Unicode_characters ).
2022-02-01 23:20:23 +08:00
#### Axis/Border style
Option: `style` \
Values:
2023-03-10 21:15:01 +08:00
0. `style_types.ASCII` : ASCII
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
1. `style_types.basic` : Basic
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
2. `style_types.light` : Light (default)
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
3. `style_types.heavy` : Heavy
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
4. `style_types.double` : Double
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
5. `style_types.light_dashed` : Light Dashed
2022-02-01 23:20:23 +08:00

2023-03-10 21:15:01 +08:00
6. `style_types.heavy_dashed` : Heavy Dashed
2022-02-01 23:20:23 +08:00

#### Graph/Plot Color
Option: `color` \
Values:
2023-03-10 21:15:01 +08:00
0. `color_types.default` : System default
1. `color_types.black` : Black
2. `color_types.red` : Red (default)
3. `color_types.green` : Green
4. `color_types.yellow` : Yellow
5. `color_types.blue` : Blue
2023-03-13 22:29:43 +08:00
6. `color_types.magenta` : Magenta
7. `color_types.cyan` : Cyan
8. `color_types.dark_gray` : Light Gray
9. `color_types.dark_gray` : Dark Gray
10. `color_types.light_red` : Light Red
11. `color_types.light_green` : Light Green
12. `color_types.light_yellow` : Light Yellow
13. `color_types.light_blue` : Light Blue
14. `color_types.light_magenta` : Light Magenta
15. `color_types.light_cyan` : Light Cyan
16. `color_types.white` : White
2022-02-01 23:20:23 +08:00
See [here ](https://misc.flogisoft.com/bash/tip_colors_and_formatting#foreground_text ) for examples of the colors.
2023-03-13 22:29:43 +08:00
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.
2022-02-01 23:20:23 +08:00
##### Plot

##### Graph

2023-03-10 21:15:01 +08:00
#### Check size
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.