A lightweight package to plot brain surfaces with Python.
Project description
This is a Python package that plots data on cortical surface.
Installation
The package can be installed with pip:
pip install brainplotlib
Example usage
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
:
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 cv2
.
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
@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}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
brainplotlib-0.4.1.tar.gz
(8.2 MB
view hashes)
Built Distribution
Close
Hashes for brainplotlib-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52063d680552c4823b2507039eadd79357da9352c700db8c74d5a7e6c3656717 |
|
MD5 | 4f4cc568ba3aa307ac5af57b249b41a7 |
|
BLAKE2b-256 | 2b6631a44747c822a93e6b309c42bf0a295b85f91128fcb9b927ec4dd4591566 |