Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed color range and added show_cbar option in plot_swanson_vector #12

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions iblatlas/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,8 @@ def plot_scalar_on_barplot(acronyms, values, errors=None, order=True, ax=None, b

def plot_swanson_vector(acronyms=None, values=None, ax=None, hemisphere=None, br=None, orientation='landscape',
empty_color='silver', vmin=None, vmax=None, cmap='viridis', annotate=False, annotate_n=10,
annotate_order='top', annotate_list=None, mask=None, mask_color='w', fontsize=10, **kwargs):
annotate_order='top', annotate_list=None, mask=None, mask_color='w', fontsize=10,
show_cbar=False, extend='neither', **kwargs):
"""
Function to plot scalar value per allen region on the swanson projection. Plots on a vecortised version of the
swanson projection
Expand All @@ -854,8 +855,12 @@ def plot_swanson_vector(acronyms=None, values=None, ax=None, hemisphere=None, br
Minimum value to restrict the colormap
vmax: float
Maximum value to restrict the colormap
cmap: string
matplotlib named colormap to use
cmap: string or matplotlib.colors.Colormap
matplotlib colormap to use
show_cbar: bool, default=False
Whether to display a colorbar.
extend: str, default='neither'
Which side of the colorbar to extend. See `colorbar` documentation.
annotate : bool, default=False
If true, labels the regions with acronyms.
annotate_n: int
Expand Down Expand Up @@ -886,6 +891,8 @@ def plot_swanson_vector(acronyms=None, values=None, ax=None, hemisphere=None, br
if ax is None:
fig, ax = plt.subplots()
ax.set_axis_off()
else:
fig = ax.get_figure()

if hemisphere != 'both' and acronyms is not None and not isinstance(acronyms[0], str):
# If negative atlas ids are passed in and we are not going to lateralise (e.g hemisphere='both')
Expand All @@ -894,11 +901,22 @@ def plot_swanson_vector(acronyms=None, values=None, ax=None, hemisphere=None, br

if acronyms is not None:
ibr, vals = br.propagate_down(acronyms, values)
colormap = matplotlib.colormaps.get_cmap(cmap)
vmin = vmin or np.nanmin(vals)
vmax = vmax or np.nanmax(vals)

if isinstance(cmap, matplotlib.colors.Colormap):
colormap = cmap
elif isinstance(cmap, str):
colormap = matplotlib.colormaps.get_cmap(cmap)
else:
raise ValueError("`cmap` option must be of type `str` or `matplotlib.colors.Colormap`")

vmin = vmin if vmin is not None else np.nanmin(vals)
vmax = vmax if vmax is not None else np.nanmax(vals)
norm = colors.Normalize(vmin=vmin, vmax=vmax)
rgba_color = colormap(norm(vals), bytes=True)
if show_cbar:
fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap),
ax=ax, orientation='vertical', extend=extend,
)

if mask is not None:
imr, _ = br.propagate_down(mask, np.ones_like(mask))
Expand Down
Loading