Create two-dimensional plots on a picture template using the example of a 2D brain map.
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].
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.
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:
- Template preparation in inkscape
- Plotting the data on this template with Python
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.
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_pathspecifies the path to the SVG template. - The
dest_pathspecifies the destination path to the SVG output. - The
region_name_listlists the names of the overlay regions of the SVG template. - The
region_value_listlists the values you want to plot on the template. The values are sorted in the same order as theregion_name_listand 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_rangedefines the lower and upper limits of the color scale in the form of a tuple. - By default,
scaleis 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
scaleis set to True: Thescale_tick_positionslists the tick positions of the color scale. It is advisable to use the twoscale_rangevalues as the first and last value of the list. - Relevant if
scaleis set to True: you can modify the path where the color scale should be saved with the variablescale_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.
To get a taste of it, you can use the random brainmap data provided in this repository.
- Install inkscape. The code was tested with inkscape version 1.4.
- Download the template_map. Now you should be able to open this template_map with inkscape.
- The plotting code runs with Python 3.10.12. You need to install the python packages listed at the beginning of inkscape_brainmap.py.
- Run inkscape_brainmap.py with default parameters. It will plot example data that is supplied within the code.
- Open the generated output file (default name brainmap_v1.svg) with inkscape.
- The corresponding color scale is saved in a separate file scale_v1.png.
- Have fun!
This project is licensed under the MIT License.
[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