Metadata-Version: 2.1
Name: brainplotlib
Version: 0.5.0
Summary: A lightweight package to plot brain surfaces with Python.
Home-page: https://feilong.github.io/brainplotlib/
Author: Ma Feilong
Author-email: mafeilong@gmail.com
License: UNKNOWN
Project-URL: Bug Tracker, https://github.com/feilong/brainplotlib/issues
Project-URL: Source Code, https://github.com/feilong/brainplotlib
Keywords: brain,surface,fmri,plotting,visualization
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Provides-Extra: tests

![PyPI](https://img.shields.io/pypi/v/brainplotlib)
![PyPI - Downloads](https://img.shields.io/pypi/dm/brainplotlib)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5979819.svg)](https://doi.org/10.5281/zenodo.5979819)

`brainplotlib` is a Python package that plots data on cortical surface.
It's designed to have minimal requirements --- only `NumPy` and `matplotlib`.

![brain image](https://github.com/feilong/brainplotlib/raw/main/images/random_data_with_colorbar.png)

## Installation
The package can be installed with pip:
```bash
pip install brainplotlib
```

## Example usage

**See the [examples gallery](https://feilong.github.io/brainplotlib/examples/index.html) for all code examples with detailed explanations.**

```Python
import numpy as np
from brainplotlib import brain_plot

## Generate some random data
# In this case it's icoorder3 resolution (642 vertices per hemisphere), and
# the non-cortical vertices have been masked out (588 and 587 remaining
# vertices for the left and right hemisphere, respectively).
rng = np.random.default_rng(0)
v = rng.random((1175, ))

img, scale = brain_plot(v, vmax=1, vmin=0, cmap='viridis', return_scale=True)
```

The rendered image is a NumPy array.
It can be rendered using `matplotlib`:
```Python
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(img.shape[1] / 200, img.shape[0] / 200), dpi=200)
plt.imshow(img)
plt.axis('off')
cbar = plt.colorbar(scale, shrink=0.8, aspect=30)
plt.savefig('random_data_with_colorbar.png', bbox_inches='tight')
plt.show()
```

Alternatively, the high-resolution image can be saved directly using `OpenCV`.
```Python
import cv2
cv2.imwrite(
    'random_data.png',
    np.round(img[:, :, [2, 1, 0]] * 255).astype(np.uint8))
```

## Citation
If you use this software in your publications, please cite it [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5979819.svg)](https://doi.org/10.5281/zenodo.5979819)
```bibtex
@software{brainplotlib,
  author       = {Ma Feilong and Guo Jiahui and M. Ida Gobbini and James V. Haxby},
  title        = {brainplotlib: plotting brain data on cortical surface},
  month        = feb,
  year         = 2022,
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.5979819},
  url          = {https://doi.org/10.5281/zenodo.5979819}
}
```


