5
5
6
6
This example demonstrates how to create the 17 segment model for the left
7
7
ventricle recommended by the American Heart Association (AHA).
8
+
9
+ .. redirect-from:: /gallery/specialty_plots/leftventricle_bulleye
8
10
"""
9
11
10
12
import numpy as np
@@ -135,15 +137,11 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
135
137
136
138
137
139
# 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' ))
140
143
fig .canvas .manager .set_window_title ('Left Ventricle Bulls Eyes (AHA)' )
141
144
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
-
147
145
148
146
# Set the colormap and norm to correspond to the data for which
149
147
# the colorbar will be used.
@@ -152,14 +150,16 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
152
150
# Create an empty ScalarMappable to set the colorbar's colormap and norm.
153
151
# The following gives a basic continuous colorbar with ticks and labels.
154
152
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' )
156
155
157
156
158
157
# And again for the second colorbar.
159
158
cmap2 = mpl .cm .cool
160
159
norm2 = mpl .colors .Normalize (vmin = 1 , vmax = 17 )
161
160
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' )
163
163
164
164
165
165
# 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):
173
173
bounds = [2 , 3 , 7 , 9 , 15 ]
174
174
norm3 = mpl .colors .BoundaryNorm (bounds , cmap3 .N )
175
175
fig .colorbar (mpl .cm .ScalarMappable (cmap = cmap3 , norm = norm3 ),
176
- cax = axl3 ,
176
+ cax = axs [ 2 ]. inset_axes ([ 0 , - .15 , 1 , .1 ]) ,
177
177
extend = 'both' ,
178
178
ticks = bounds , # optional
179
179
spacing = 'proportional' ,
@@ -182,14 +182,14 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
182
182
183
183
184
184
# 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)' )
187
187
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)' )
190
190
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 ],
192
192
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' )
194
194
195
195
plt .show ()
0 commit comments