Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions examples/flame_matplotlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Example: Flame Chart with Matplotlib Backend

This example demonstrates how to create a flame chart visualization
using the matplotlib backend. Flame charts are useful for visualizing
hierarchical profiling data, showing function call stacks and their
execution times.
"""

from maxplotlib import Canvas

# Example profiling data: function call hierarchy
# Each function has: label, parent index (None for root), and duration
labels = [
"main()", # 0 - root
"process_data()", # 1 - child of main
"load_file()", # 2 - child of process_data
"parse_json()", # 3 - child of process_data
"validate()", # 4 - child of process_data
"compute()", # 5 - child of main
"algorithm_a()", # 6 - child of compute
"algorithm_b()", # 7 - child of compute
"save_results()", # 8 - child of main
]

parents = [
None, # main() is root
0, # process_data() called by main()
1, # load_file() called by process_data()
1, # parse_json() called by process_data()
1, # validate() called by process_data()
0, # compute() called by main()
5, # algorithm_a() called by compute()
5, # algorithm_b() called by compute()
0, # save_results() called by main()
]

# Duration of each function call (in milliseconds)
values = [100, 40, 10, 15, 15, 50, 25, 25, 10]

# Start times for each function (when they begin execution)
start_times = [0, 0, 0, 10, 25, 40, 40, 65, 90]

# Create canvas and add flame chart
canvas = Canvas(nrows=1, ncols=1, figsize=(12, 6))
canvas.flame_chart(
labels=labels,
parents=parents,
values=values,
start_times=start_times,
colormap="viridis",
edgecolor="black",
)

# Configure the plot
canvas.set_xlabel("Time (ms)")
canvas.set_ylabel("Stack Depth")
canvas.set_title("Flame Chart: Function Call Hierarchy")

# Save the figure
canvas.savefig("flame_matplotlib.png", backend="matplotlib")
print("Flame chart saved as flame_matplotlib.png")
58 changes: 58 additions & 0 deletions examples/flame_plotext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Example: Flame Chart with Plotext Backend

This example demonstrates how to create a flame chart visualization
using the plotext backend for terminal/console output.
"""

from maxplotlib import Canvas

# Example profiling data: function call hierarchy
labels = [
"main()", # 0 - root
"process_data()", # 1 - child of main
"load_file()", # 2 - child of process_data
"parse_json()", # 3 - child of process_data
"validate()", # 4 - child of process_data
"compute()", # 5 - child of main
"algorithm_a()", # 6 - child of compute
"algorithm_b()", # 7 - child of compute
"save_results()", # 8 - child of main
]

parents = [
None, # main() is root
0, # process_data() called by main()
1, # load_file() called by process_data()
1, # parse_json() called by process_data()
1, # validate() called by process_data()
0, # compute() called by main()
5, # algorithm_a() called by compute()
5, # algorithm_b() called by compute()
0, # save_results() called by main()
]

# Duration of each function call (in milliseconds)
values = [100, 40, 10, 15, 15, 50, 25, 25, 10]

# Start times for each function (when they begin execution)
start_times = [0, 0, 0, 10, 25, 40, 40, 65, 90]

# Create canvas and add flame chart
canvas = Canvas(nrows=1, ncols=1)
canvas.flame_chart(
labels=labels,
parents=parents,
values=values,
start_times=start_times,
colormap="viridis",
)

# Configure the plot
canvas.set_xlabel("Time (ms)")
canvas.set_ylabel("Stack Depth")
canvas.set_title("Flame Chart: Function Call Hierarchy")

# Save the figure
canvas.savefig("flame_plotext.txt", backend="plotext")
print("Flame chart saved as flame_plotext.txt")
60 changes: 60 additions & 0 deletions examples/flame_plotly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Example: Flame Chart with Plotly Backend

This example demonstrates how to create an interactive flame chart
using the plotly backend. The interactive nature allows zooming and
hovering over function calls to see details.
"""

from maxplotlib import Canvas

# Example profiling data: function call hierarchy
labels = [
"main()", # 0 - root
"process_data()", # 1 - child of main
"load_file()", # 2 - child of process_data
"parse_json()", # 3 - child of process_data
"validate()", # 4 - child of process_data
"compute()", # 5 - child of main
"algorithm_a()", # 6 - child of compute
"algorithm_b()", # 7 - child of compute
"save_results()", # 8 - child of main
]

parents = [
None, # main() is root
0, # process_data() called by main()
1, # load_file() called by process_data()
1, # parse_json() called by process_data()
1, # validate() called by process_data()
0, # compute() called by main()
5, # algorithm_a() called by compute()
5, # algorithm_b() called by compute()
0, # save_results() called by main()
]

# Duration of each function call (in milliseconds)
values = [100, 40, 10, 15, 15, 50, 25, 25, 10]

# Start times for each function (when they begin execution)
start_times = [0, 0, 0, 10, 25, 40, 40, 65, 90]

# Create canvas and add flame chart
canvas = Canvas(nrows=1, ncols=1, figsize=(12, 6))
canvas.flame_chart(
labels=labels,
parents=parents,
values=values,
start_times=start_times,
colormap="Plasma",
edgecolor="black",
)

# Configure the plot
canvas.set_xlabel("Time (ms)")
canvas.set_ylabel("Stack Depth")
canvas.set_title("Interactive Flame Chart: Function Call Hierarchy")

# Save the figure
canvas.savefig("flame_plotly.html", backend="plotly")
print("Interactive flame chart saved as flame_plotly.html")
57 changes: 57 additions & 0 deletions examples/flame_tikz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Example: Flame Chart with TikzFigure Backend

This example demonstrates how to create a flame chart visualization
using the tikzfigure backend for LaTeX/PDF output.
"""

from maxplotlib import Canvas

# Example profiling data: function call hierarchy
labels = [
"main()", # 0 - root
"process_data()", # 1 - child of main
"load_file()", # 2 - child of process_data
"parse_json()", # 3 - child of process_data
"validate()", # 4 - child of process_data
"compute()", # 5 - child of main
"algorithm_a()", # 6 - child of compute
"algorithm_b()", # 7 - child of compute
"save_results()", # 8 - child of main
]

parents = [
None, # main() is root
0, # process_data() called by main()
1, # load_file() called by process_data()
1, # parse_json() called by process_data()
1, # validate() called by process_data()
0, # compute() called by main()
5, # algorithm_a() called by compute()
5, # algorithm_b() called by compute()
0, # save_results() called by main()
]

# Duration of each function call (in milliseconds)
values = [100, 40, 10, 15, 15, 50, 25, 25, 10]

# Start times for each function (when they begin execution)
start_times = [0, 0, 0, 10, 25, 40, 40, 65, 90]

# Create canvas and add flame chart
canvas = Canvas(nrows=1, ncols=1)
canvas.flame_chart(
labels=labels,
parents=parents,
values=values,
start_times=start_times,
)

# Configure the plot
canvas.set_xlabel("Time (ms)")
canvas.set_ylabel("Stack Depth")
canvas.set_title("Flame Chart: Function Call Hierarchy")

# Save the figure
canvas.savefig("flame_tikz.pdf", backend="tikzfigure")
print("Flame chart saved as flame_tikz.pdf")
50 changes: 50 additions & 0 deletions examples/gantt_matplotlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import numpy as np

from maxplotlib import Canvas


def main() -> None:
# Define project tasks
tasks = [
"Planning",
"Design",
"Development",
"Testing",
"Deployment",
"Documentation",
]

# Start times (in days from project start)
start_times = np.array([0, 5, 10, 25, 35, 30])

# Duration of each task (in days)
durations = np.array([5, 5, 15, 10, 5, 10])

# Create canvas
canvas = Canvas(width="14cm", ratio=0.6, dpi=150)

# Add gantt chart
canvas.gantt(
tasks=tasks,
start_times=start_times,
durations=durations,
color="steelblue",
alpha=0.7,
edgecolor="black",
label="Project Tasks",
)

# Configure plot
canvas.set_title("Project Timeline - Gantt Chart")
canvas.set_xlabel("Days from Project Start")
canvas.set_ylabel("Tasks")
canvas.set_grid(True)
canvas.set_xlim(0, 45)

# Save figure
canvas.savefig("gantt_matplotlib.png", backend="matplotlib")
print("Gantt chart saved as gantt_matplotlib.png")


if __name__ == "__main__":
main()
48 changes: 48 additions & 0 deletions examples/gantt_plotext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import numpy as np

from maxplotlib import Canvas


def main() -> None:
# Define project tasks
tasks = [
"Planning",
"Design",
"Development",
"Testing",
"Deployment",
"Documentation",
]

# Start times (in days from project start)
start_times = np.array([0, 5, 10, 25, 35, 30])

# Duration of each task (in days)
durations = np.array([5, 5, 15, 10, 5, 10])

# Create canvas
canvas = Canvas(width="14cm", ratio=0.6)

# Add gantt chart
canvas.gantt(
tasks=tasks,
start_times=start_times,
durations=durations,
color="cyan",
label="Project Tasks",
)

# Configure plot
canvas.set_title("Project Timeline - Gantt Chart (Plotext)")
canvas.set_xlabel("Days from Project Start")
canvas.set_ylabel("Tasks")
canvas.set_grid(True)
canvas.set_xlim(0, 45)

# Save figure (plotext renders to terminal)
canvas.savefig("gantt_plotext.txt", backend="plotext")
print("Gantt chart saved as gantt_plotext.txt")


if __name__ == "__main__":
main()
49 changes: 49 additions & 0 deletions examples/gantt_plotly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import numpy as np

from maxplotlib import Canvas


def main() -> None:
# Define project tasks
tasks = [
"Planning",
"Design",
"Development",
"Testing",
"Deployment",
"Documentation",
]

# Start times (in days from project start)
start_times = np.array([0, 5, 10, 25, 35, 30])

# Duration of each task (in days)
durations = np.array([5, 5, 15, 10, 5, 10])

# Create canvas
canvas = Canvas(width="14cm", ratio=0.6)

# Add gantt chart
canvas.gantt(
tasks=tasks,
start_times=start_times,
durations=durations,
color="steelblue",
alpha=0.7,
label="Project Tasks",
)

# Configure plot
canvas.set_title("Project Timeline - Gantt Chart (Plotly)")
canvas.set_xlabel("Days from Project Start")
canvas.set_ylabel("Tasks")
canvas.set_grid(True)
canvas.set_xlim(0, 45)

# Save figure
canvas.savefig("gantt_plotly.html", backend="plotly")
print("Gantt chart saved as gantt_plotly.html")


if __name__ == "__main__":
main()
Loading
Loading