Skip to main content
Rich output capture automatically detects and captures visual outputs like matplotlib plots, pandas DataFrames, and plotly charts from your code execution.

Prerequisites

Before you begin, make sure you have:
  • Active sandbox - A running sandbox (see Creating Sandboxes)
  • Understanding of code execution - Familiarity with Synchronous Execution is helpful
  • Code that generates visualizations - Code that creates plots, DataFrames, or charts

Overview

When you execute code with run_code(), HopX automatically captures:
  • Matplotlib plots → PNG images (base64-encoded)
  • Pandas DataFrames → HTML tables
  • Plotly charts → HTML interactive visualizations
  • JSON outputs → Structured data
Rich output capture is enabled by default in run_code(). All visual outputs are automatically detected and included in the ExecutionResult.rich_outputs array.

Automatic Capture

Rich outputs are captured automatically:

Matplotlib Plots

Capture matplotlib plots as PNG images:

Pandas DataFrames

Capture pandas DataFrames as HTML tables:

Plotly Charts

Capture interactive Plotly charts as HTML:

Multiple Rich Outputs

Capture multiple outputs in a single execution:

Rich Output Structure

Each rich output has the following structure:

Complete Example

Here’s a complete example with all rich output types:

Best Practices

1

1. Save Files Explicitly

Always save plots to files (e.g., plt.savefig()) to ensure they’re captured. Rich output capture works best when files are explicitly saved.
2

2. Use Appropriate Formats

  • Matplotlib: Save as PNG for best compatibility
  • Pandas: Print DataFrames to trigger HTML capture
  • Plotly: Use write_html() for interactive charts
3

3. Check Output Count

Use len(result.rich_outputs) to verify all expected outputs were captured.
4

4. Handle Base64 Encoding

PNG images are base64-encoded. Decode them before displaying or saving locally.
5

5. Multiple Outputs

You can capture multiple plots/DataFrames in a single execution. All will be included in rich_outputs.

Next Steps