How to Create a Plot
A quick guide to using the plot system to visualize section data in 2D or 3D.
The Basics
The plot system has three main pieces:
- PlotService - Manages all the plot data and settings
- StudioComponent - The container that sets everything up
- SectionPlotComponent - Actually draws the plot
When you give StudioComponent a section, it automatically:
1. Waits for the Python worker to be ready
2. Fetches the section data
3. Passes it to SectionPlotComponent to render
Quick Start
Just use the StudioComponent in your template:
1 2 3 4 | |
The component handles loading states and errors automatically. That's it!
Changing Plot Options
Use PlotService to change how the plot looks:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Available Options
1 2 3 4 5 6 7 | |
How It Works
Data Flow
- You provide a
sectiontoStudioComponent StudioComponentcallsplotService.refreshSection(section)- The service fetches data from the Python worker
- Data flows into
SectionPlotComponentvia signals - The plot automatically updates when data or options change
Plot Rendering
SectionPlotComponent uses an Angular effect() to watch for changes. When data arrives, it:
- Transforms the raw data into Plotly format
- Creates the plot in a <div id="plotly-output"> element
- Preserves camera position in 3D mode
Common Tasks
Recalculate with Different Climate Parameters
1 2 3 4 5 | |
Get Current Camera Position
1 2 | |
Reset Everything
1 | |
Error Handling
The system handles errors automatically. Common errors:
- NO_CABLE_FOUND - Cable data missing
- CALCULATION_ERROR - Calculation failed
- SOLVER_DID_NOT_CONVERGE - Solver couldn't find solution
- PYODIDE_LOAD_ERROR - Python worker didn't load
Errors show up in the StudioComponent template automatically.
Cleanup
Don't forget to clean up when your component is destroyed:
1 2 3 4 5 6 | |
Full Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
Tips
- The plot updates automatically when data or options change - you usually don't need to manually refresh
- Always use
plotOptionsChange()instead of directly setting options - Camera position is preserved automatically in 3D mode
- Make sure the Python worker is ready before calling
refreshSection()