CalcTree Help Pages
  • What is CalcTree?
  • Getting started
    • CalcTree Pages
    • Create a CalcTree Page
    • Add a calculation
    • Collaborate with a colleague
  • Calculations
    • Parameters
      • Math formulas
        • Parameter Data Types
        • Native Functions
          • Arithmetic Functions
          • Trigonometric Functions
          • Logical & Comparison Functions
          • Matrix & Vector Functions
          • Probability & Combinatorics Functions
          • Statistical Functions
          • String Functions
          • Utility Functions
          • Other Native Functions
        • Valid Expression Syntax
      • Supported Units
      • Dropdown List Parameters
        • Linking CSV Data to Dependent Dropdowns in CalcTree
      • Parameter Settings
    • Integrations
      • Python in CalcTree
        • Adding a Python Source
        • Defining Parameters in Python
        • Referencing Other Parameters in Python
        • Working with Units in Python
        • Creating Tables and Visuals in Python
        • Consuming Files in Python
        • Using Pre-installed Python Libraries
      • Spreadsheets [Coming Soon!]
      • File Upload
        • CSV files
      • 3rd Party Software Plugins
        • Excel
        • Grasshopper
        • ETABS [v20 & v21]
        • ETABS [v22]
        • SAP 2000
        • CSI Bridge [v26]
    • Templates [Coming Soon!]
    • Optimising your calculations
  • Pages & Reports
    • CalcTree Documents
    • Static content
    • Parametric content
      • Parametric equation
      • Inputs
      • Outputs
  • Export to PDF
  • API
    • GraphQL API
      • Generating an API key
      • Queries
        • GetCalculation
        • Calculate
      • Examples
        • Bulk calculations with Python
  • Collaborate
    • Add members
    • Review and approval
    • Add stakeholders
  • Administrate
    • CalcTree Workspace
    • Versioning and Audit trail
  • CalcTree for System Administrators
Powered by GitBook
On this page
  • Creating Tables
  • Generating Visuals
  • Notes
  1. Calculations
  2. Integrations
  3. Python in CalcTree

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

PreviousWorking with Units in PythonNextConsuming Files in Python

Last updated 1 day ago

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

here