Skip to content

Commit f96d44d

Browse files
committed
docs: add English documentation files
1 parent 61725ba commit f96d44d

File tree

77 files changed

+1407
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1407
-0
lines changed

docs/en/api/index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# API
2+
3+
::: plotfig.single_bar
4+
5+
::: plotfig.multi_bars
6+
7+
::: plotfig.correlation
8+
9+
::: plotfig.matrix
10+
11+
::: plotfig.brain_surface
12+
13+
::: plotfig.circos
14+
15+
::: plotfig.brain_connection
16+
17+
::: plotfig.utils

docs/en/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
Automatically updated!

docs/en/index.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Introduction
2+
3+
`plotfig` is a Python library designed specifically for scientific data visualization, dedicated to providing efficient, easy-to-use, and beautiful plotting tools for cognitive neuroscience researchers.
4+
This project is developed based on mainstream visualization libraries in the industry—`matplotlib`, `surfplot`, and `plotly`, integrating their powerful features to meet the complex plotting needs in neuroscience and brain connectomics across various scenarios.
5+
6+
![plotfig](../assets/plotfig.png)
7+
8+
## Project Structure
9+
10+
The project adopts a modular design, containing the following main functional modules:
11+
12+
- `bar.py`: Bar chart plotting, suitable for comparative display of grouped data.
13+
- `matrix.py`: General matrix visualization, supporting multiple color schemes and annotation methods.
14+
- `correlation.py`: Correlation matrix visualization, facilitating analysis of correlation distributions between variables.
15+
- `circos.py`: Circos plot visualization, suitable for planar display of connections between brain regions.
16+
- `brain_surface.py`: Brain surface visualization, enabling plotting of 3D brain surface atlas structures.
17+
- `brain_connection.py`: Glass brain connectivity visualization, supporting complex brain network structure display.
18+
19+
## Features
20+
21+
- The `plotfig` API has a simple design with flexible parameters, making it suitable for researchers and data analysts to quickly integrate into their data analysis workflows.
22+
- Its modular architecture facilitates future feature expansion and custom development.
23+
- Combined with `matplotlib`, it supports vector graphics, high-resolution bitmap, and interactive HTML output, suitable for paper publication and academic presentation.
24+
25+
---
26+
27+
Fun fact: All elements of a figure[^1].
28+
![Parts of a Figure](https://matplotlib.org/stable/_images/anatomy.png)
29+
30+
[^1]: [Quick start guide of matplotlib.](https://matplotlib.org/stable/tutorials/introductory/usage.html#parts-of-a-figure)

docs/en/installation.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Installation
2+
3+
`plotfig` supports installation via package managers or directly from source, requiring Python 3.11 or higher.
4+
5+
## Install via Package Manager (Recommended)
6+
7+
=== "uv"
8+
9+
```bash
10+
uv add plotfig
11+
```
12+
13+
=== "pip"
14+
15+
```bash
16+
pip install plotfig
17+
```
18+
19+
## Install from Source
20+
21+
First, download the source code to a directory (e.g., `/path/to/plotfig`):
22+
23+
```bash
24+
git clone https://github.com/RicardoRyn/plotfig.git /path/to/plotfig
25+
```
26+
27+
Then execute the following in your project directory:
28+
29+
=== "uv"
30+
31+
```bash
32+
uv add /path/to/plotfig
33+
```
34+
35+
=== "pip"
36+
37+
```bash
38+
pip install /path/to/plotfig
39+
```
40+
41+
!!! info
42+
43+
`/path/to/plotfig` should be replaced with the actual path.
44+
45+
## Contributing
46+
47+
If you wish to experience these features or participate in `plotfig` development, you can choose to install the project in editable mode.
48+
49+
This installation mode allows your modifications to the local source code to take effect immediately, making it very suitable for debugging, development, and contributing code.
50+
51+
Recommended workflow:
52+
53+
1. Fork this repository to your GitHub account
54+
2. Clone your fork locally:
55+
```bash
56+
git clone https://github.com/USERNAME/plotfig.git /path/to/plotfig
57+
```
58+
3. Install in editable mode in your project directory:
59+
60+
=== "uv"
61+
62+
```bash
63+
uv add --editable /path/to/plotfig
64+
```
65+
66+
=== "pip"
67+
68+
```bash
69+
pip install -e /path/to/plotfig
70+
```
71+
72+
!!! info
73+
74+
`/path/to/plotfig` should be replaced with the actual path.
75+
76+
---
77+
78+
**We welcome Issues and PRs!**
79+
80+
Whether it's bug reports, feature suggestions, or documentation improvements.
81+
82+
Feel free to open an [Issue](https://github.com/RicardoRyn/plotfig/issues).
83+
84+
You can also submit a [PR](https://github.com/RicardoRyn/plotfig/pulls) directly to help us grow stronger 💪!
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Brain Connectivity Plot
2+
3+
Transparent brain plot that can display connectivity relationships between brain regions.
4+
You need to prepare surface files for left and right hemispheres, brain region-related nii.gz files, and a connectivity matrix.
5+
6+
## Quick Plot
7+
8+
For all parameters, see the API documentation for [`plot_brain_connection_figure`](../api/#plotfig.brain_connection.plot_brain_connection_figure).
9+
10+
```python
11+
from plotfig import plot_brain_connection_figure, gen_symmetric_matrix
12+
13+
# Generate random connectivity matrix
14+
connectome = gen_symmetric_matrix(31, sparsity=0.1, seed=42)
15+
16+
# Left and right brain surface files and network node files need to be provided by yourself
17+
lh_surfgii_file = r"example_data/103818.L.midthickness.32k_fs_LR.surf.gii"
18+
rh_surfgii_file = r"example_data/103818.R.midthickness.32k_fs_LR.surf.gii"
19+
niigz_file = r"example_data/network.nii.gz"
20+
21+
# HTML file output location
22+
output_file = "example_data/brain_connection.html"
23+
24+
fig = plot_brain_connection_figure(
25+
connectome,
26+
lh_surfgii_file=lh_surfgii_file,
27+
rh_surfgii_file=rh_surfgii_file,
28+
niigz_file=niigz_file,
29+
output_file=output_file,
30+
scale_method="width",
31+
line_width=10,
32+
nodes_name=[f"ROI_{i}" for i in range(connectome.shape[0])],
33+
)
34+
```
35+
36+
## Result Display
37+
38+
![output](brain_connectivity_files/output.gif)
39+
40+
The HTML file can be interactively viewed in a browser. You can manually take screenshots, or use the following command to batch generate multi-view images.
41+
42+
```python
43+
from pathlib import Path
44+
from plotfig import save_brain_connection_frames
45+
46+
# Create new folder to save frame images
47+
Path(f"./example_data/brain_connection_figures").mkdir(parents=True, exist_ok=True)
48+
save_brain_connection_frames(
49+
fig,
50+
output_dir=rf"./example_data/brain_connection_figures",
51+
n_frames=36
52+
)
53+
```
54+
55+
100%|██████████| 36/36 [01:55<00:00, 3.19s/it]
56+
2025-11-24 11:02:55.867 | INFO | plotfig.brain_connection:save_brain_connection_frames:323 - Saved 36 images in ./example_data/brain_connection_figures
57+
58+
plotfig provides a utility function to combine image sequences into GIF animations.
59+
60+
```python
61+
from pathlib import Path
62+
from plotfig import create_gif_from_images
63+
64+
create_gif_from_images(
65+
Path("example_data/brain_connection_figures"),
66+
output_name="output.gif"
67+
)
68+
```
69+
70+
2025-11-24 11:07:46.885 | INFO | plotfig.brain_connection:create_gif_from_images:417 - GIF saved to: example_data\brain_connection_figures\outpug.gif
2.88 MB
Loading

docs/en/usage/brain_surface.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Brain Surface Plot
2+
3+
Brain surface plot is a chart used to visualize numerical data on the cerebral cortex surface.
4+
It can map values of different brain regions to corresponding areas of the cerebral cortex and display the distribution of these values in a color-coded manner.
5+
This type of chart is commonly used to display various brain region metrics in neuroscience research, such as BOLD signal intensity, myelination degree, volume or thickness, or other quantifiable brain features.
6+
7+
The `plot_brain_surface_figure` function is developed based on the `surfplot` library, providing a unified and simplified interface for plotting brain surface maps for human, macaque, and chimpanzee brains.
8+
Currently supports multiple brain atlases including:
9+
10+
1. Human Glasser (HCP-MMP) atlas[^1]. [Atlas CSV file](../assets/atlas_csv/human_glasser.csv).
11+
1. Human BNA atlas[^2]. [Atlas CSV file](../assets/atlas_csv/human_bna.csv).
12+
1. Chimpanzee BNA atlas[^3]. [Atlas CSV file](../assets/atlas_csv/chimpanzee_bna.csv).
13+
1. Macaque CHARM 5-level[^4]. [Atlas CSV file](../assets/atlas_csv/macaque_charm5.csv).
14+
1. Macaque CHARM 6-level[^4]. [Atlas CSV file](../assets/atlas_csv/macaque_charm6.csv).
15+
1. Macaque BNA atlas[^5]. [Atlas CSV file](../assets/atlas_csv/macaque_bna.csv).
16+
1. Macaque D99 atlas[^6]. [Atlas CSV file](../assets/atlas_csv/macaque_d99.csv).
17+
18+
[^1]:
19+
Glasser, M. F., Coalson, T. S., Robinson, E. C., Hacker, C. D., Harwell, J., Yacoub, E., Ugurbil, K., Andersson, J., Beckmann, C. F., Jenkinson, M., Smith, S. M., & Van Essen, D. C. (2016). A multi-modal parcellation of human cerebral cortex. Nature, 536(7615), Article 7615. https://doi.org/10.1038/nature18933
20+
[^2]:
21+
Fan, L., Li, H., Zhuo, J., Zhang, Y., Wang, J., Chen, L., Yang, Z., Chu, C., Xie, S., Laird, A. R., Fox, P. T., Eickhoff, S. B., Yu, C., & Jiang, T. (2016). The Human Brainnetome Atlas: A New Brain Atlas Based on Connectional Architecture. Cerebral Cortex (New York, N.Y.: 1991), 26(8), 3508–3526. https://doi.org/10.1093/cercor/bhw157
22+
[^3]:
23+
Wang, Y., Cheng, L., Li, D., Lu, Y., Wang, C., Wang, Y., Gao, C., Wang, H., Erichsen, C. T., Vanduffel, W., Hopkins, W. D., Sherwood, C. C., Jiang, T., Chu, C., & Fan, L. (2025). The Chimpanzee Brainnetome Atlas reveals distinct connectivity and gene expression profiles relative to humans. The Innovation, 0(0). https://doi.org/10.1016/j.xinn.2024.100755
24+
[^4]:
25+
Jung, B., Taylor, P. A., Seidlitz, J., Sponheim, C., Perkins, P., Ungerleider, L. G., Glen, D., & Messinger, A. (2021). A comprehensive macaque fMRI pipeline and hierarchical atlas. NeuroImage, 235, 117997. https://doi.org/10.1016/j.neuroimage.2021.117997
26+
[^5]:
27+
Lu, Y., Cui, Y., Cao, L., Dong, Z., Cheng, L., Wu, W., Wang, C., Liu, X., Liu, Y., Zhang, B., Li, D., Zhao, B., Wang, H., Li, K., Ma, L., Shi, W., Li, W., Ma, Y., Du, Z., … Jiang, T. (2024). Macaque Brainnetome Atlas: A multifaceted brain map with parcellation, connection, and histology. Science Bulletin, 69(14), 2241–2259. https://doi.org/10.1016/j.scib.2024.03.031
28+
[^6]:
29+
Reveley, C., Gruslys, A., Ye, F. Q., Glen, D., Samaha, J., E. Russ, B., Saad, Z., K. Seth, A., Leopold, D. A., & Saleem, K. S. (2017). Three-Dimensional Digital Template Atlas of the Macaque Brain. Cerebral Cortex, 27(9), 4463–4477. https://doi.org/10.1093/cercor/bhw248
30+
31+
## Quick Plot
32+
33+
!!! info
34+
Please ensure brain region names are correct before plotting.
35+
36+
```python
37+
from plotfig import plot_brain_surface_figure
38+
39+
data = {"lh_V1": 1, "rh_MT": 1.5}
40+
41+
ax = plot_brain_surface_figure(data, species="human", atlas="glasser")
42+
```
43+
44+
![png](brain_surface_files/brain_surface_4_0.png)
45+
46+
```python
47+
from plotfig import plot_brain_surface_figure
48+
import matplotlib.pyplot as plt
49+
50+
macaque_data = {"lh_V1": 1}
51+
chimpanzee_data = {"lh_MVOcC.rv": 1}
52+
53+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))
54+
55+
ax1 = plot_brain_surface_figure(
56+
chimpanzee_data, species="chimpanzee", atlas="bna", ax=ax1, title_name="Chimpanzee"
57+
)
58+
ax2 = plot_brain_surface_figure(
59+
macaque_data, species="macaque", atlas="charm5", ax=ax2, title_name="Macaque"
60+
)
61+
```
62+
63+
![png](brain_surface_files/brain_surface_5_0.png)
64+
65+
## Different Surface Files
66+
67+
For humans, the following surface files are provided:
68+
69+
1. `veryinflated`
70+
2. `inflated`
71+
3. `midthiickness`
72+
4. `sphere`
73+
5. `flat`
74+
75+
```python
76+
from plotfig import plot_brain_surface_figure
77+
import matplotlib.pyplot as plt
78+
79+
fig, axes = plt.subplots(2, 3, figsize=(12, 6))
80+
fig.delaxes(axes[1, 2])
81+
82+
plot_data = {"lh_V1": 1, "rh_FST": 2}
83+
84+
ax1 = plot_brain_surface_figure(plot_data, surf="veryinflated", ax=axes[0,0], title_name="veryinflated")
85+
ax2 = plot_brain_surface_figure(plot_data, surf="inflated", ax=axes[0,1], title_name="inflated")
86+
ax3 = plot_brain_surface_figure(plot_data, surf="midthickness", ax=axes[0, 2], title_name="midthickness")
87+
ax4 = plot_brain_surface_figure(plot_data, surf="sphere", ax=axes[1,0], title_name="sphere")
88+
ax5 = plot_brain_surface_figure(plot_data, surf="flat", ax=axes[1,1], title_name="flat")
89+
```
90+
91+
![png](brain_surface_files/brain_surface_8_0.png)
92+
93+
For chimpanzees, the following surface files are provided:
94+
95+
1. `veryinflated`
96+
2. `midthiickness`
97+
98+
```python
99+
from plotfig import plot_brain_surface_figure
100+
import matplotlib.pyplot as plt
101+
102+
fig, axes = plt.subplots(1, 2)
103+
104+
plot_data = {"lh_MVOcC.rd": 1, "rh_STG.r": 2}
105+
106+
ax1 = plot_brain_surface_figure(plot_data, species="chimpanzee", atlas="bna", surf="veryinflated", ax=axes[0], title_name="veryinflated")
107+
ax3 = plot_brain_surface_figure(plot_data, species="chimpanzee", atlas="bna", surf="midthickness", ax=axes[1], title_name="midthickness")
108+
```
109+
110+
![png](brain_surface_files/brain_surface_10_0.png)
111+
112+
For macaques, the following surface files are provided:
113+
114+
1. `veryinflated`
115+
2. `inflated`
116+
4. `pial`
117+
3. `midthiickness`
118+
5. `white`
119+
6. `flat`
120+
121+
```python
122+
from plotfig import plot_brain_surface_figure
123+
import matplotlib.pyplot as plt
124+
125+
fig, axes = plt.subplots(2, 3, figsize=(12, 6))
126+
127+
plot_data = {"lh_V1": 1, "rh_FST": 2}
128+
129+
ax1 = plot_brain_surface_figure(plot_data, species="macaque", atlas="charm5", surf="veryinflated", ax=axes[0,0], title_name="veryinflated")
130+
ax2 = plot_brain_surface_figure(plot_data, species="macaque", atlas="charm5", surf="inflated", ax=axes[0,1], title_name="inflated")
131+
ax3 = plot_brain_surface_figure(plot_data, species="macaque", atlas="charm5", surf="pial", ax=axes[0, 2], title_name="pial")
132+
ax4 = plot_brain_surface_figure(plot_data, species="macaque", atlas="charm5", surf="midthickness", ax=axes[1,0], title_name="midthickness")
133+
ax5 = plot_brain_surface_figure(plot_data, species="macaque", atlas="charm5", surf="white", ax=axes[1,1], title_name="white")
134+
ax6 = plot_brain_surface_figure(plot_data, species="macaque", atlas="charm5", surf="flat", ax=axes[1,2], title_name="flat")
135+
```
136+
137+
![png](brain_surface_files/brain_surface_12_0.png)
138+
139+
## More Settings
140+
141+
For all parameters, see the API documentation for [`plot_brain_surface_figure`](../api/#plotfig.brain_surface.plot_brain_surface_figure).
142+
143+
```python
144+
from plotfig import plot_brain_surface_figure
145+
146+
data = {"lh_V1": 1, "rh_MT": 1.5, "rh_V1": -1}
147+
148+
ax = plot_brain_surface_figure(
149+
data,
150+
species="human",
151+
atlas="glasser",
152+
surf="inflated",
153+
cmap="bwr",
154+
vmin=-1,
155+
vmax=1,
156+
colorbar=True,
157+
colorbar_label_name="AAA"
158+
)
159+
```
160+
161+
![png](brain_surface_files/brain_surface_15_0.png)
46.2 KB
Loading
46.2 KB
Loading
170 KB
Loading

0 commit comments

Comments
 (0)