brainglobe / brainglobe-heatmap

Rendering anatomical heatmaps with brainrender and matplotlib
https://brainglobe.info
MIT License
34 stars 10 forks source link

[Feature] Refactor API for plotting multiple 2D slices from the same dataset at different distances. #54

Open IgorTatarnikov opened 3 months ago

IgorTatarnikov commented 3 months ago

Is your feature request related to a problem? Please describe. The newly added Heatmap.plot_subplot() could have a better public facing API. Right now a separate scene is created for each subplot, this can cause a segmentation fault if the reference to each scene isn't kept between the plot_subplot() call and the call to plt.show().

Describe the solution you'd like We could allow a scene to be initialised with more than one slicing location. The plot() function would then either provide a single plot if only one slicing location is provided or a plot with multiple subplots if multiple positions were passed during initialisation.

This would generate a single plot at position 8000:

scene = bgh.Heatmap(
    data_dict,
    position=8000,
    orientation="frontal",
    thickness=10,
    format="2D",
    cmap="Reds",
    vmin=0,
    vmax=1,
    label_regions=False,
).plot()

This would generate a plot with 6 subplots:

scene = bgh.Heatmap(
    data_dict,
    position=[7500, 8000, 8500, 9000, 9500, 10000],
    orientation="frontal",
    thickness=10,
    format="2D",
    cmap="Reds",
    vmin=0,
    vmax=1,
    label_regions=False,
).plot()

This is just one idea, the position argument already has a few meaning depending on the dimensionality of the visualisation and the specific type passed (tuple vs ndarray).

See discussion in #44.