# Adding Custom Visualization Functions

If you want to visualize data or results from a specific pipeline step — for example, neuron activity, motion correction results, or event detections — you can easily integrate visualization libraries such as **Matplotlib**.

There are two main approaches depending on your experience level:

***

**1. Quick & Simple: Add a Custom Method in `pipeline.py`**

If you just want to visualize results quickly, you can define a new method directly in the `CIPipe` class inside:

ci\_pipe/\
└─ pipeline.py <-- modify this file

For example:

```
def my_function_matplot_view_neurons(self, step_number):
    self._plotter.get_neurons_step(
        self._trace_repository.load(),
        self._branch_name,
        step_number
    )
```

Then, in your script or notebook, you can call:

```
pipeline.my_function_matplot_view_neurons(step_nro=3)
```

This approach uses the internal `Plotter` class to display formatted results (with Rich tables and panels) and can be easily extended to include graphical visualizations.

***

**2. Recommended for Developers: Create or Extend a Plotter**

If you are comfortable with programming and want a cleaner or more modular design, you can extend the visualization system directly in:

ci\_pipe/\
└─ plotter.py <-- modify this file

You can add a new import for Matplotlib and define your own visualization function:

```
import matplotlib.pyplot as plt

class Plotter:
    ...
    def get_neurons_step(self, trace, branch, step_number):
        step = self._get_step(trace, step_number, branch)
        if not step:
            return

        neuron_data = step["outputs"].get("neurons", [])
        plt.figure(figsize=(8, 4))
        plt.plot(neuron_data)
        plt.title(f"Neuron activity – step {step_number}")
        plt.show()
```

**Best Practice**

* If you have **basic or limited Python knowledge**, simply add a helper method in `pipeline.py`.
* If you are a **developer or advanced user**, extend or create a new `Plotter` class — this keeps your visualization logic modular and easier to maintain.
* You can also build specialized plotters (e.g., `IsxPlotter`, `QCPlotter`, `EventPlotter`) and integrate them into the pipeline using the same internal `Plotter` interface.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cipipe.gitbook.io/cipipe-docs/expansion-guide/adding-custom-visualization-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
