Creating Tables and Visuals in Python

Display tabular data and visual outputs directly from your Python calculations using list-based tables and matplotlib figures.

Python sources in CalcTree support both tabular data and visual outputs such as plots and charts. This allows you to include structured results and engineering figures directly within your calculation pages.

Creating Tables

To create a table, define a root-level Python variable as a list of lists. Each inner list will be treated as a row in the table.

Example:

my_table = [
    [1, "apple"],
    ["cat", 3.14]
]

This will display a 2-row table under the Python source block on the right-hand panel.

Generating Visuals

You can use the matplotlib library to create charts and plots. If your Python source includes a matplotlib figure, CalcTree will automatically detect and display it below the script.

Example:

import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots()
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)',
       title='Sine Wave Example')
ax.grid()

The figure will appear in the output panel below your Python code. Click the three-dot menu, and 'intsert parameter' to add the figure to anywhere in your page.

Notes

  • Only matplotlib figures are currently supported

  • Tables must be declared as simple list-of-list objects at the root level

  • Both outputs update live as you edit your code or parameters on the page linked to these elements

You can learn more about creating various charts or diagrams using the Matplotlib library here

Last updated