Skip to content

Commit 53694c1

Browse files
committed
Cleanup bullseye plot example.
Fix typo in filename. Tighten axes layout, and use relative coordinates to position colorbars instead of hardcoded absolute positions (which become wrong as soon as the figure size changes).
1 parent 7a909fd commit 53694c1

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

examples/specialty_plots/leftventricle_bulleye.py renamed to examples/specialty_plots/leftventricle_bullseye.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
This example demonstrates how to create the 17 segment model for the left
77
ventricle recommended by the American Heart Association (AHA).
8+
9+
.. redirect-from:: /gallery/specialty_plots/leftventricle_bulleye
810
"""
911

1012
import numpy as np
@@ -135,15 +137,11 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
135137

136138

137139
# Make a figure and axes with dimensions as desired.
138-
fig, ax = plt.subplots(figsize=(12, 8), nrows=1, ncols=3,
139-
subplot_kw=dict(projection='polar'))
140+
fig = plt.figure(figsize=(10, 5), layout="constrained")
141+
fig.get_layout_engine().set(wspace=.1, w_pad=.2)
142+
axs = fig.subplots(1, 3, subplot_kw=dict(projection='polar'))
140143
fig.canvas.manager.set_window_title('Left Ventricle Bulls Eyes (AHA)')
141144

142-
# Create the axis for the colorbars
143-
axl = fig.add_axes([0.14, 0.15, 0.2, 0.05])
144-
axl2 = fig.add_axes([0.41, 0.15, 0.2, 0.05])
145-
axl3 = fig.add_axes([0.69, 0.15, 0.2, 0.05])
146-
147145

148146
# Set the colormap and norm to correspond to the data for which
149147
# the colorbar will be used.
@@ -152,14 +150,16 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
152150
# Create an empty ScalarMappable to set the colorbar's colormap and norm.
153151
# The following gives a basic continuous colorbar with ticks and labels.
154152
fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap, norm=norm),
155-
cax=axl, orientation='horizontal', label='Some Units')
153+
cax=axs[0].inset_axes([0, -.15, 1, .1]),
154+
orientation='horizontal', label='Some Units')
156155

157156

158157
# And again for the second colorbar.
159158
cmap2 = mpl.cm.cool
160159
norm2 = mpl.colors.Normalize(vmin=1, vmax=17)
161160
fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap2, norm=norm2),
162-
cax=axl2, orientation='horizontal', label='Some other units')
161+
cax=axs[1].inset_axes([0, -.15, 1, .1]),
162+
orientation='horizontal', label='Some other units')
163163

164164

165165
# The second example illustrates the use of a ListedColormap, a
@@ -173,7 +173,7 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
173173
bounds = [2, 3, 7, 9, 15]
174174
norm3 = mpl.colors.BoundaryNorm(bounds, cmap3.N)
175175
fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap3, norm=norm3),
176-
cax=axl3,
176+
cax=axs[2].inset_axes([0, -.15, 1, .1]),
177177
extend='both',
178178
ticks=bounds, # optional
179179
spacing='proportional',
@@ -182,14 +182,14 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
182182

183183

184184
# Create the 17 segment model
185-
bullseye_plot(ax[0], data, cmap=cmap, norm=norm)
186-
ax[0].set_title('Bulls Eye (AHA)')
185+
bullseye_plot(axs[0], data, cmap=cmap, norm=norm)
186+
axs[0].set_title('Bulls Eye (AHA)')
187187

188-
bullseye_plot(ax[1], data, cmap=cmap2, norm=norm2)
189-
ax[1].set_title('Bulls Eye (AHA)')
188+
bullseye_plot(axs[1], data, cmap=cmap2, norm=norm2)
189+
axs[1].set_title('Bulls Eye (AHA)')
190190

191-
bullseye_plot(ax[2], data, seg_bold=[3, 5, 6, 11, 12, 16],
191+
bullseye_plot(axs[2], data, seg_bold=[3, 5, 6, 11, 12, 16],
192192
cmap=cmap3, norm=norm3)
193-
ax[2].set_title('Segments [3, 5, 6, 11, 12, 16] in bold')
193+
axs[2].set_title('Segments [3, 5, 6, 11, 12, 16] in bold')
194194

195195
plt.show()

0 commit comments

Comments
 (0)