Skip to content

Commit 3fac121

Browse files
committed
FIX workaround for ax.inset_axes in matplotlib < 3.0
1 parent 224ea14 commit 3fac121

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

voxelwise_tutorials/viz.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ def plot_flatmap_from_mapper(voxels, mapper_file, ax=None, alpha=0.7,
135135
vmin=vmin, vmax=vmax)
136136

137137
if with_colorbar:
138-
cbar = ax.inset_axes(colorbar_location)
138+
try:
139+
cbar = ax.inset_axes(colorbar_location)
140+
except AttributeError: # for matplotlib < 3.0
141+
cbar = ax.figure.add_axes(colorbar_location)
139142
ax.figure.colorbar(cimg, cax=cbar, orientation='horizontal')
140143

141144
# plot additional layers if present
@@ -293,7 +296,10 @@ def plot_2d_flatmap_from_mapper(voxels_1, voxels_2, mapper_file, ax=None,
293296
ax.imshow(image, aspect='equal', zorder=1, alpha=alpha)
294297

295298
if with_colorbar:
296-
cbar = ax.inset_axes(colorbar_location)
299+
try:
300+
cbar = ax.inset_axes(colorbar_location)
301+
except AttributeError: # for matplotlib < 3.0
302+
cbar = ax.figure.add_axes(colorbar_location)
297303
cbar.imshow(cmap_image, aspect='equal',
298304
extent=(vmin, vmax, vmin2, vmax2))
299305
cbar.set(xlabel=label_1, ylabel=label_2)

0 commit comments

Comments
 (0)