Skip to content

cor2ni/2D_brain_plot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2D brain plot

Create two-dimensional plots on a picture template using the example of a 2D brain map.

Demo
The figure shows randomly colored brain regions in coronal view on template slices of the gyral Allen Human Brain Atlas. Allen Reference Atlas – Human Brain (brain atlas), 2025 [1] [2].

Idea

Visualization of scores across brain regions is common in neuroimaging studies. However, the available atlases and softwares are sometimes not sufficient for a specific purpose. For example, the regions you want to visualize may not match the available areas of a template, or other individual modifications may be restricted. This manual provides and explains tools to create your individual plot with automated coloring. It is independent from applications to the brain and can be modified for every 2D image plot.

Refer to 3D brain plot for three-dimensional plotting.

How to create a plot

For this plot, we use the advantages of both sites, a user-friendly software with a graphical interface for image creation, and Python for automated coloring. There are two steps to generate a 2D image plot:

  1. Template preparation in inkscape
  2. Plotting the data on this template with Python

1. Template preparation

The template is built as a Scalable Vector Graphic (SVG file), easily accessible and modifiable via the free design tool inkscape. It consists of two components:

  • A background image, e.g., black and white slices of the gyral Allen Human Brain Atlas. Allen Reference Atlas – Human Brain (brain atlas), 2025 [1] [2]. However, any picture can be imported as a background image.
  • Overlaying paths in the shapes of your regions of interest. Every path has to be named uniquely so that you can set the colors individually later on. You can use the functions in inkscape to create new forms and rename them at your choice.

2. Plotting

While plotting, color and opacity values are assigned to the overlays of the template. The following parameters can be modified in the code inkscape_brainmap.py:

  • The template_path specifies the path to the SVG template.
  • The dest_path specifies the destination path to the SVG output.
  • The region_name_list lists the names of the overlay regions of the SVG template.
  • The region_value_list lists the values you want to plot on the template. The values are sorted in the same order as the region_name_list and both lists should have the same length. If there is no value available for one region, this value should be set to NaN. NaN values are plotted transparently.
  • The scale_range defines the lower and upper limits of the color scale in the form of a tuple.
  • By default, scale is set to True. Thus, a color scale is plotted and saved as a separate file. Set it to False if no color scale plot is needed.
  • Relevant if scale is set to True: The scale_tick_positions lists the tick positions of the color scale. It is advisable to use the two scale_range values ​​as the first and last value of the list.
  • Relevant if scale is set to True: you can modify the path where the color scale should be saved with the variable scale_name. By default, it is set to scale_v1.png.

After parameter setting, run the code inkscape_brainmap.py to plot your data on the SVG template. After that, you can open the SVG output file defined in dest_path with inkscape. It will show the brainmap with plotted colors corresponding to the color scale.

Run an example

To get a taste of it, you can use the random brainmap data provided in this repository.

  1. Install inkscape. The code was tested with inkscape version 1.4.
  2. Download the template_map. Now you should be able to open this template_map with inkscape.
  3. The plotting code runs with Python 3.10.12. You need to install the python packages listed at the beginning of inkscape_brainmap.py.
  4. Run inkscape_brainmap.py with default parameters. It will plot example data that is supplied within the code.
  5. Open the generated output file (default name brainmap_v1.svg) with inkscape.
  6. The corresponding color scale is saved in a separate file scale_v1.png.
  7. Have fun!

License

This project is licensed under the MIT License.

References

[1] Allen Reference Atlas – Human Brain [brain atlas]. Available from atlas.brain-map.org., 2025
[2] Ding, S.-L., Royall, J.J., Sunkin, S.M., Ng, L., Facer, B.A.C., Lesnar, P., Guillozet-Bongaarts, A., McMurray, B., Szafer, A., Dolbeare, T.A., Stevens, A., Tirrell, L., Benner, T., Caldejon, S., Dalley, R.A., Dee, N., Lau, C., Nyhus, J., Reding, M., Riley, Z.L., Sandman, D., Shen, E., van der Kouwe, A., Varjabedian, A., Write, M., Zollei, L., Dang, C., Knowles, J.A., Koch, C., Phillips, J.W., Sestan, N., Wohnoutka, P., Zielke, H.R., Hohmann, J.G., Jones, A.R., Bernard, A., Hawrylycz, M.J., Hof, P.R., Fischl, B., Lein, E.S., 2016. Comprehensive cellular-resolution atlas of the adult human brain. Journal of Comparative Neurology 524, 3127–3481. https://doi.org/10.1002/cne.24080

About

Create two-dimensional plots on a picture template using the example of a 2D brain map.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages