2022-07-14 16:33:38 +08:00
|
|
|
#!/usr/bin/env python3
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
# Teal Dulcet, CS546
|
|
|
|
|
2023-08-30 20:57:03 +08:00
|
|
|
# Run: python3 -OO test.py
|
|
|
|
|
2023-05-11 22:03:53 +08:00
|
|
|
import math
|
2022-02-01 23:20:23 +08:00
|
|
|
import random
|
|
|
|
import sys
|
2023-05-11 22:03:53 +08:00
|
|
|
|
2022-02-01 23:20:23 +08:00
|
|
|
import graphs
|
|
|
|
import tables
|
|
|
|
|
|
|
|
|
2023-05-11 22:03:53 +08:00
|
|
|
def afunction(x: float):
|
2023-03-13 22:29:43 +08:00
|
|
|
return x + 1
|
|
|
|
|
|
|
|
|
2023-05-11 22:03:53 +08:00
|
|
|
def function1(x: float):
|
2023-03-13 22:29:43 +08:00
|
|
|
return 2 * x
|
|
|
|
|
|
|
|
|
2023-05-11 22:03:53 +08:00
|
|
|
def function2(x: float):
|
2023-03-13 22:29:43 +08:00
|
|
|
return x ** 2
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
rows = 5
|
|
|
|
columns = 5
|
|
|
|
|
|
|
|
xmin = -10
|
|
|
|
xmax = 10
|
2023-03-10 21:15:01 +08:00
|
|
|
xstep = 0.5
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
print("\nOutput array as table\n")
|
|
|
|
array = [[random.randint(0, sys.maxsize)
|
|
|
|
for j in range(columns)] for i in range(rows)]
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in tables.style_types:
|
|
|
|
tables.array(array, None, None, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
array = [[random.random() for j in range(columns)] for i in range(rows)]
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in tables.style_types:
|
|
|
|
tables.array(array, None, None, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
print("\nOutput char array as table\n")
|
|
|
|
array = [["Header row/column 1", "Header row 2", "Header row 3", "Header row 4", "Header row 5"],
|
|
|
|
["Header column 2", "Data 1", "Data 2", "Data 3", "Data 4"],
|
|
|
|
["Header column 3", "Data 5", "Data 6", "Data 7", "Data 8"],
|
|
|
|
["Header column 4", "Data 9", "Data 10", "Data 11", "Data 12"],
|
|
|
|
["Header column 5", "Data 13", "Data 14", "Data 15", "Data 16"]]
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in tables.style_types:
|
|
|
|
tables.array(array, None, None, headerrow=True,
|
|
|
|
headercolumn=True, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
print("\nOutput array as table with separate header row and column\n")
|
2023-05-11 22:03:53 +08:00
|
|
|
array = [[f"Data {i + j:n}" for j in range(4)]
|
2022-02-01 23:20:23 +08:00
|
|
|
for i in range(1, 4 * 4 + 1, 4)]
|
|
|
|
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"]
|
|
|
|
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in tables.style_types:
|
|
|
|
tables.array(array, headerrow, headercolumn, headerrow=True,
|
|
|
|
headercolumn=True, cellborder=True, style=style)
|
|
|
|
tables.array(array, headerrow, headercolumn,
|
|
|
|
headerrow=True, headercolumn=True, style=style)
|
|
|
|
tables.array(array, headerrow[:-1], None, headerrow=True, style=style)
|
|
|
|
tables.array(array, None, [headerrow[0]] +
|
|
|
|
headercolumn[:-1], headercolumn=True, style=style)
|
|
|
|
tables.array(array, None, None, cellborder=True, style=style)
|
|
|
|
tables.array(array, None, None, tableborder=False, style=style)
|
|
|
|
tables.array(array, headerrow, headercolumn, tableborder=False,
|
|
|
|
headerrow=True, headercolumn=True, style=style)
|
|
|
|
tables.array(array, headerrow[:-1], None,
|
|
|
|
tableborder=False, headerrow=True, style=style)
|
|
|
|
tables.array(array, None, [headerrow[0]] + headercolumn[:-1],
|
|
|
|
tableborder=False, headercolumn=True, style=style)
|
|
|
|
tables.array(array, None, None, tableborder=False,
|
|
|
|
cellborder=True, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
array = [[bool(random.getrandbits(1)) for j in range(columns)]
|
|
|
|
for i in range(rows)]
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in tables.style_types:
|
|
|
|
tables.array(array, None, None, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
print("\nOutput sorted array as table\n")
|
|
|
|
array = ([random.randint(0, sys.maxsize)
|
|
|
|
for j in range(columns)] for i in range(rows))
|
|
|
|
sortdimension = 0
|
|
|
|
array = sorted(array, key=lambda x: x[sortdimension])
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in tables.style_types:
|
|
|
|
tables.array(array, None, None, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
print("\nOutput single function as table\n")
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in tables.style_types:
|
|
|
|
tables.function(xmin, xmax, xstep, afunction, headerrow=True, style=style)
|
|
|
|
for style in tables.style_types:
|
|
|
|
tables.function(xmin, xmax, xstep, lambda x: x +
|
|
|
|
1, headerrow=True, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
print("\nOutput multiple functions as table\n")
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in tables.style_types:
|
|
|
|
tables.functions(xmin, xmax, xstep, [
|
|
|
|
function1, function2], headerrow=True, style=style)
|
|
|
|
for style in tables.style_types:
|
|
|
|
tables.functions(xmin, xmax, xstep, [
|
|
|
|
lambda x: 2 * x, lambda x: x ** 2], headerrow=True, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
height = 160
|
|
|
|
width = 160
|
|
|
|
|
|
|
|
xmin = -20
|
|
|
|
xmax = 20
|
|
|
|
ymin = -20
|
|
|
|
ymax = 20
|
|
|
|
|
2023-08-30 20:57:03 +08:00
|
|
|
print("\nOutput array as histogram\n")
|
|
|
|
array = [random.gauss(0, 1) for i in range(100)]
|
|
|
|
for style in graphs.style_types:
|
|
|
|
graphs.histogram(height, width, xmin, xmax, ymin, ymax, array, style=style)
|
|
|
|
|
2022-07-14 16:33:38 +08:00
|
|
|
print("\nOutput single array as plot\n")
|
|
|
|
array = [range(i, i + 2) for i in range(10)]
|
2023-08-30 20:57:03 +08:00
|
|
|
for atype in graphs.atype_types:
|
|
|
|
for mark in graphs.mark_types:
|
|
|
|
for style in graphs.style_types:
|
|
|
|
graphs.plot(height, width, xmin, xmax, ymin, ymax,
|
|
|
|
array, atype=atype, mark=mark, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
print("\nOutput single function as graph\n")
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in graphs.style_types:
|
2022-07-14 16:33:38 +08:00
|
|
|
graphs.function(height, width, xmin, xmax, ymin,
|
2023-03-10 21:15:01 +08:00
|
|
|
ymax, afunction, style=style)
|
|
|
|
for style in graphs.style_types:
|
|
|
|
graphs.function(height, width, xmin, xmax, ymin,
|
|
|
|
ymax, lambda x: x + 1, style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
|
|
|
print("\nOutput multiple functions as graph\n")
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in graphs.style_types:
|
|
|
|
graphs.functions(height, width, xmin, xmax, ymin, ymax,
|
|
|
|
[function1, function2], style=style)
|
|
|
|
for style in graphs.style_types:
|
2022-07-14 16:33:38 +08:00
|
|
|
graphs.functions(height, width, xmin, xmax, ymin, ymax, [
|
2023-03-10 21:15:01 +08:00
|
|
|
lambda x: 2 * x, lambda x: x ** 2], style=style)
|
2022-02-01 23:20:23 +08:00
|
|
|
|
2023-03-10 21:15:01 +08:00
|
|
|
for style in graphs.style_types:
|
|
|
|
graphs.functions(height, width, -(2 * math.pi), 2 * math.pi, -4, 4,
|
|
|
|
[math.sin, math.cos, math.tan], axisunitslabel=False, style=style)
|