Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #24955 on branch v3.7.x (Cleanup bullseye plot example.) #24956

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

This example demonstrates how to create the 17 segment model for the left
ventricle recommended by the American Heart Association (AHA).

.. redirect-from:: /gallery/specialty_plots/leftventricle_bulleye
"""

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


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

# Create the axis for the colorbars
axl = fig.add_axes([0.14, 0.15, 0.2, 0.05])
axl2 = fig.add_axes([0.41, 0.15, 0.2, 0.05])
axl3 = fig.add_axes([0.69, 0.15, 0.2, 0.05])


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


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


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


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

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

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

plt.show()