Skip to content

Commit 35915da

Browse files
authored
Merge pull request #53 from max-models/devel
Version 0.1.5
2 parents b6a1986 + 3cbfa4a commit 35915da

15 files changed

Lines changed: 2118 additions & 1 deletion

examples/flame_matplotlib.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
Example: Flame Chart with Matplotlib Backend
3+
4+
This example demonstrates how to create a flame chart visualization
5+
using the matplotlib backend. Flame charts are useful for visualizing
6+
hierarchical profiling data, showing function call stacks and their
7+
execution times.
8+
"""
9+
10+
from maxplotlib import Canvas
11+
12+
# Example profiling data: function call hierarchy
13+
# Each function has: label, parent index (None for root), and duration
14+
labels = [
15+
"main()", # 0 - root
16+
"process_data()", # 1 - child of main
17+
"load_file()", # 2 - child of process_data
18+
"parse_json()", # 3 - child of process_data
19+
"validate()", # 4 - child of process_data
20+
"compute()", # 5 - child of main
21+
"algorithm_a()", # 6 - child of compute
22+
"algorithm_b()", # 7 - child of compute
23+
"save_results()", # 8 - child of main
24+
]
25+
26+
parents = [
27+
None, # main() is root
28+
0, # process_data() called by main()
29+
1, # load_file() called by process_data()
30+
1, # parse_json() called by process_data()
31+
1, # validate() called by process_data()
32+
0, # compute() called by main()
33+
5, # algorithm_a() called by compute()
34+
5, # algorithm_b() called by compute()
35+
0, # save_results() called by main()
36+
]
37+
38+
# Duration of each function call (in milliseconds)
39+
values = [100, 40, 10, 15, 15, 50, 25, 25, 10]
40+
41+
# Start times for each function (when they begin execution)
42+
start_times = [0, 0, 0, 10, 25, 40, 40, 65, 90]
43+
44+
# Create canvas and add flame chart
45+
canvas = Canvas(nrows=1, ncols=1, figsize=(12, 6))
46+
canvas.flame_chart(
47+
labels=labels,
48+
parents=parents,
49+
values=values,
50+
start_times=start_times,
51+
colormap="viridis",
52+
edgecolor="black",
53+
)
54+
55+
# Configure the plot
56+
canvas.set_xlabel("Time (ms)")
57+
canvas.set_ylabel("Stack Depth")
58+
canvas.set_title("Flame Chart: Function Call Hierarchy")
59+
60+
# Save the figure
61+
canvas.savefig("flame_matplotlib.png", backend="matplotlib")
62+
print("Flame chart saved as flame_matplotlib.png")

examples/flame_plotext.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Example: Flame Chart with Plotext Backend
3+
4+
This example demonstrates how to create a flame chart visualization
5+
using the plotext backend for terminal/console output.
6+
"""
7+
8+
from maxplotlib import Canvas
9+
10+
# Example profiling data: function call hierarchy
11+
labels = [
12+
"main()", # 0 - root
13+
"process_data()", # 1 - child of main
14+
"load_file()", # 2 - child of process_data
15+
"parse_json()", # 3 - child of process_data
16+
"validate()", # 4 - child of process_data
17+
"compute()", # 5 - child of main
18+
"algorithm_a()", # 6 - child of compute
19+
"algorithm_b()", # 7 - child of compute
20+
"save_results()", # 8 - child of main
21+
]
22+
23+
parents = [
24+
None, # main() is root
25+
0, # process_data() called by main()
26+
1, # load_file() called by process_data()
27+
1, # parse_json() called by process_data()
28+
1, # validate() called by process_data()
29+
0, # compute() called by main()
30+
5, # algorithm_a() called by compute()
31+
5, # algorithm_b() called by compute()
32+
0, # save_results() called by main()
33+
]
34+
35+
# Duration of each function call (in milliseconds)
36+
values = [100, 40, 10, 15, 15, 50, 25, 25, 10]
37+
38+
# Start times for each function (when they begin execution)
39+
start_times = [0, 0, 0, 10, 25, 40, 40, 65, 90]
40+
41+
# Create canvas and add flame chart
42+
canvas = Canvas(nrows=1, ncols=1)
43+
canvas.flame_chart(
44+
labels=labels,
45+
parents=parents,
46+
values=values,
47+
start_times=start_times,
48+
colormap="viridis",
49+
)
50+
51+
# Configure the plot
52+
canvas.set_xlabel("Time (ms)")
53+
canvas.set_ylabel("Stack Depth")
54+
canvas.set_title("Flame Chart: Function Call Hierarchy")
55+
56+
# Save the figure
57+
canvas.savefig("flame_plotext.txt", backend="plotext")
58+
print("Flame chart saved as flame_plotext.txt")

examples/flame_plotly.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
Example: Flame Chart with Plotly Backend
3+
4+
This example demonstrates how to create an interactive flame chart
5+
using the plotly backend. The interactive nature allows zooming and
6+
hovering over function calls to see details.
7+
"""
8+
9+
from maxplotlib import Canvas
10+
11+
# Example profiling data: function call hierarchy
12+
labels = [
13+
"main()", # 0 - root
14+
"process_data()", # 1 - child of main
15+
"load_file()", # 2 - child of process_data
16+
"parse_json()", # 3 - child of process_data
17+
"validate()", # 4 - child of process_data
18+
"compute()", # 5 - child of main
19+
"algorithm_a()", # 6 - child of compute
20+
"algorithm_b()", # 7 - child of compute
21+
"save_results()", # 8 - child of main
22+
]
23+
24+
parents = [
25+
None, # main() is root
26+
0, # process_data() called by main()
27+
1, # load_file() called by process_data()
28+
1, # parse_json() called by process_data()
29+
1, # validate() called by process_data()
30+
0, # compute() called by main()
31+
5, # algorithm_a() called by compute()
32+
5, # algorithm_b() called by compute()
33+
0, # save_results() called by main()
34+
]
35+
36+
# Duration of each function call (in milliseconds)
37+
values = [100, 40, 10, 15, 15, 50, 25, 25, 10]
38+
39+
# Start times for each function (when they begin execution)
40+
start_times = [0, 0, 0, 10, 25, 40, 40, 65, 90]
41+
42+
# Create canvas and add flame chart
43+
canvas = Canvas(nrows=1, ncols=1, figsize=(12, 6))
44+
canvas.flame_chart(
45+
labels=labels,
46+
parents=parents,
47+
values=values,
48+
start_times=start_times,
49+
colormap="Plasma",
50+
edgecolor="black",
51+
)
52+
53+
# Configure the plot
54+
canvas.set_xlabel("Time (ms)")
55+
canvas.set_ylabel("Stack Depth")
56+
canvas.set_title("Interactive Flame Chart: Function Call Hierarchy")
57+
58+
# Save the figure
59+
canvas.savefig("flame_plotly.html", backend="plotly")
60+
print("Interactive flame chart saved as flame_plotly.html")

examples/flame_tikz.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Example: Flame Chart with TikzFigure Backend
3+
4+
This example demonstrates how to create a flame chart visualization
5+
using the tikzfigure backend for LaTeX/PDF output.
6+
"""
7+
8+
from maxplotlib import Canvas
9+
10+
# Example profiling data: function call hierarchy
11+
labels = [
12+
"main()", # 0 - root
13+
"process_data()", # 1 - child of main
14+
"load_file()", # 2 - child of process_data
15+
"parse_json()", # 3 - child of process_data
16+
"validate()", # 4 - child of process_data
17+
"compute()", # 5 - child of main
18+
"algorithm_a()", # 6 - child of compute
19+
"algorithm_b()", # 7 - child of compute
20+
"save_results()", # 8 - child of main
21+
]
22+
23+
parents = [
24+
None, # main() is root
25+
0, # process_data() called by main()
26+
1, # load_file() called by process_data()
27+
1, # parse_json() called by process_data()
28+
1, # validate() called by process_data()
29+
0, # compute() called by main()
30+
5, # algorithm_a() called by compute()
31+
5, # algorithm_b() called by compute()
32+
0, # save_results() called by main()
33+
]
34+
35+
# Duration of each function call (in milliseconds)
36+
values = [100, 40, 10, 15, 15, 50, 25, 25, 10]
37+
38+
# Start times for each function (when they begin execution)
39+
start_times = [0, 0, 0, 10, 25, 40, 40, 65, 90]
40+
41+
# Create canvas and add flame chart
42+
canvas = Canvas(nrows=1, ncols=1)
43+
canvas.flame_chart(
44+
labels=labels,
45+
parents=parents,
46+
values=values,
47+
start_times=start_times,
48+
)
49+
50+
# Configure the plot
51+
canvas.set_xlabel("Time (ms)")
52+
canvas.set_ylabel("Stack Depth")
53+
canvas.set_title("Flame Chart: Function Call Hierarchy")
54+
55+
# Save the figure
56+
canvas.savefig("flame_tikz.pdf", backend="tikzfigure")
57+
print("Flame chart saved as flame_tikz.pdf")

examples/gantt_matplotlib.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import numpy as np
2+
3+
from maxplotlib import Canvas
4+
5+
6+
def main() -> None:
7+
# Define project tasks
8+
tasks = [
9+
"Planning",
10+
"Design",
11+
"Development",
12+
"Testing",
13+
"Deployment",
14+
"Documentation",
15+
]
16+
17+
# Start times (in days from project start)
18+
start_times = np.array([0, 5, 10, 25, 35, 30])
19+
20+
# Duration of each task (in days)
21+
durations = np.array([5, 5, 15, 10, 5, 10])
22+
23+
# Create canvas
24+
canvas = Canvas(width="14cm", ratio=0.6, dpi=150)
25+
26+
# Add gantt chart
27+
canvas.gantt(
28+
tasks=tasks,
29+
start_times=start_times,
30+
durations=durations,
31+
color="steelblue",
32+
alpha=0.7,
33+
edgecolor="black",
34+
label="Project Tasks",
35+
)
36+
37+
# Configure plot
38+
canvas.set_title("Project Timeline - Gantt Chart")
39+
canvas.set_xlabel("Days from Project Start")
40+
canvas.set_ylabel("Tasks")
41+
canvas.set_grid(True)
42+
canvas.set_xlim(0, 45)
43+
44+
# Save figure
45+
canvas.savefig("gantt_matplotlib.png", backend="matplotlib")
46+
print("Gantt chart saved as gantt_matplotlib.png")
47+
48+
49+
if __name__ == "__main__":
50+
main()

examples/gantt_plotext.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import numpy as np
2+
3+
from maxplotlib import Canvas
4+
5+
6+
def main() -> None:
7+
# Define project tasks
8+
tasks = [
9+
"Planning",
10+
"Design",
11+
"Development",
12+
"Testing",
13+
"Deployment",
14+
"Documentation",
15+
]
16+
17+
# Start times (in days from project start)
18+
start_times = np.array([0, 5, 10, 25, 35, 30])
19+
20+
# Duration of each task (in days)
21+
durations = np.array([5, 5, 15, 10, 5, 10])
22+
23+
# Create canvas
24+
canvas = Canvas(width="14cm", ratio=0.6)
25+
26+
# Add gantt chart
27+
canvas.gantt(
28+
tasks=tasks,
29+
start_times=start_times,
30+
durations=durations,
31+
color="cyan",
32+
label="Project Tasks",
33+
)
34+
35+
# Configure plot
36+
canvas.set_title("Project Timeline - Gantt Chart (Plotext)")
37+
canvas.set_xlabel("Days from Project Start")
38+
canvas.set_ylabel("Tasks")
39+
canvas.set_grid(True)
40+
canvas.set_xlim(0, 45)
41+
42+
# Save figure (plotext renders to terminal)
43+
canvas.savefig("gantt_plotext.txt", backend="plotext")
44+
print("Gantt chart saved as gantt_plotext.txt")
45+
46+
47+
if __name__ == "__main__":
48+
main()

examples/gantt_plotly.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import numpy as np
2+
3+
from maxplotlib import Canvas
4+
5+
6+
def main() -> None:
7+
# Define project tasks
8+
tasks = [
9+
"Planning",
10+
"Design",
11+
"Development",
12+
"Testing",
13+
"Deployment",
14+
"Documentation",
15+
]
16+
17+
# Start times (in days from project start)
18+
start_times = np.array([0, 5, 10, 25, 35, 30])
19+
20+
# Duration of each task (in days)
21+
durations = np.array([5, 5, 15, 10, 5, 10])
22+
23+
# Create canvas
24+
canvas = Canvas(width="14cm", ratio=0.6)
25+
26+
# Add gantt chart
27+
canvas.gantt(
28+
tasks=tasks,
29+
start_times=start_times,
30+
durations=durations,
31+
color="steelblue",
32+
alpha=0.7,
33+
label="Project Tasks",
34+
)
35+
36+
# Configure plot
37+
canvas.set_title("Project Timeline - Gantt Chart (Plotly)")
38+
canvas.set_xlabel("Days from Project Start")
39+
canvas.set_ylabel("Tasks")
40+
canvas.set_grid(True)
41+
canvas.set_xlim(0, 45)
42+
43+
# Save figure
44+
canvas.savefig("gantt_plotly.html", backend="plotly")
45+
print("Gantt chart saved as gantt_plotly.html")
46+
47+
48+
if __name__ == "__main__":
49+
main()

0 commit comments

Comments
 (0)