> For the complete documentation index, see [llms.txt](https://docs.tensorleap.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/visualizer_classes/leapgraph.md).

# LeapGraph

code\_loader.contract.visualizer\_classes.LeapGraph

Used to visualize one or more 1D signals as line plots.

```python
@dataclass
class LeapGraph:
    data: npt.NDArray[np.float32]
    type: LeapDataType = LeapDataType.Graph
    x_label: Optional[str] = None
    y_label: Optional[str] = None
    x_range: Optional[Tuple[float, float]] = None
    legend: Optional[List[str]] = None
```

| Args      |                                                                                                                                                  |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `data`    | `np.ndarray` of dtype `float32` and shape `[M, N]`: `M` points for each of `N` lines. For a single line, use shape `[M, 1]`.                     |
| `x_label` | *(str, optional)* The x-axis label.                                                                                                              |
| `y_label` | *(str, optional)* The y-axis label.                                                                                                              |
| `x_range` | *(tuple of two numbers, optional)* The x values of the first and last point. Points are spread evenly between them. Defaults to the point index. |
| `legend`  | *(List\[str], optional)* One name per line. Its length must equal `N`.                                                                           |

## Examples

#### Basic Usage

```python
import numpy as np
from code_loader.contract.visualizer_classes import LeapGraph
from code_loader.contract.enums import LeapDataType
from code_loader.inner_leap_binder.leapbinder_decorators import tensorleap_custom_visualizer


@tensorleap_custom_visualizer('signal_vs_prediction', LeapDataType.Graph)
def signal_vs_prediction(ground_truth: np.ndarray, prediction: np.ndarray) -> LeapGraph:
    gt, pred = ground_truth[0], prediction[0]          # remove the batch axis; each is [M]
    data = np.stack([gt, pred], axis=1).astype(np.float32)  # [M, 2]
    return LeapGraph(data=data, x_label='Time [s]', y_label='Amplitude',
                     x_range=(0.0, 10.0), legend=['ground truth', 'prediction'])
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/visualizer_classes/leapgraph.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
