8000 Left ventricle bull eye by curiale · Pull Request #3518 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Left ventricle bull eye #3518

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 4 commits into from
Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Added the colormap and normalize as arguments
  • Loading branch information
curiale committed Oct 18, 2014
commit 0709202aeff9eacd88880f7b3962933fd030b328
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ examples/tests/*
!examples/tests/backend_driver.py
texput.log
result_images

*.swp
117 changes: 85 additions & 32 deletions examples/pylab_examples/leftventricle_bulleye.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import matplotlib.pyplot as plt


def bullseye_plot(ax, data, vlim=None, segBold=[]):
def bullseye_plot(ax, data, segBold=[], cmap=None, norm=None):
"""
Bullseye representation for the left ventricle.

Expand All @@ -18,8 +18,10 @@ def bullseye_plot(ax, data, vlim=None, segBold=[]):
ax : axes
data : list of int and float
The intensity values for each of the 17 segments
vlim : [min, max] or None
Optional argument to set the Intensity range
cmap : ColorMap or None
Optional argument to set the disaried colormap
norm : Normalize or None
Optional argument to normalize data into the [0.0, 1.0] range
segBold: list of int
A list with the segments to highlight

Expand All @@ -33,16 +35,19 @@ def bullseye_plot(ax, data, vlim=None, segBold=[]):
----------
.. [1] M. D. Cerqueira, N. J. Weissman, V. Dilsizian, A. K. Jacobs,
S. Kaul, W. K. Laskey, D. J. Pennell, J. A. Rumberger, T. Ryan,
and M. S. Verani, Standardized myocardial segmentation and nomenclature
for tomographic imaging of the heart,” Circulation, vol. 105, no. 4,
pp. 539542, 2002.
and M. S. Verani, "Standardized myocardial segmentation and nomenclature
for tomographic imaging of the heart", Circulation, vol. 105, no. 4,
pp. 539-542, 2002.
"""

linewidth = 2
data = np.array(data).ravel()
< 8000 /td>
if vlim is None:
vlim = [data.min(), data.max()]
if cmap is None:
cmap = plt.cm.jet

if norm is None:
norm = mpl.colors.Normalize(vmin=data.min(), vmax=data.max())

theta = np.linspace(0, 2*np.pi, 768)
r = np.linspace(0.2, 1, 4)
Expand All @@ -69,7 +74,7 @@ def bullseye_plot(ax, data, vlim=None, segBold=[]):
theta0 = theta[i*128:i*128+128] + 60*np.pi/180
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
z = np.ones((128, 2))*data[i]
ax.pcolormesh(theta0, r0, z, vmin=vlim[0], vmax=vlim[1])
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
if i+1 in segBold:
ax.plot(theta0, r0, '-k', lw=linewidth+2)
ax.plot(theta0[0], [r[2], r[3]], '-k', lw=linewidth+1)
Expand All @@ -83,7 +88,7 @@ def bullseye_plot(ax, data, vlim=None, segBold=[]):
theta0 = theta[i*128:i*128+128] + 60*np.pi/180
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
z = np.ones((128, 2))*data[i+6]
ax.pcolormesh(theta0, r0, z, vmin=vlim[0], vmax=vlim[1])
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
if i+7 in segBold:
ax.plot(theta0, r0, '-k', lw=linewidth+2)
ax.plot(theta0[0], [r[1], r[2]], '-k', lw=linewidth+1)
Expand All @@ -97,7 +102,7 @@ def bullseye_plot(ax, data, vlim=None, segBold=[]):
theta0 = theta[i*192:i*192+192] + 45*np.pi/180
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
z = np.ones((192, 2))*data[i+12]
ax.pcolormesh(theta0, r0, z, vmin=vlim[0], vmax=vlim[1])
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
if i+13 in segBold:
ax.plot(theta0, r0, '-k', lw=linewidth+2)
ax.plot(theta0[0], [r[0], r[1]], '-k', lw=linewidth+1)
Expand All @@ -109,7 +114,7 @@ def bullseye_plot(ax, data, vlim=None, segBold=[]):
r0 = np.repeat(r0[:, np.newaxis], theta.size, axis=1).T
theta0 = np.repeat(theta[:, np.newaxis], 2, axis=1)
z = np.ones((theta.size, 2))*data[16]
ax.pcolormesh(theta0, r0, z, vmin=vlim[0], vmax=vlim[1])
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
if 17 in segBold:
ax.plot(theta0, r0, '-k', lw=linewidth+2)

Expand All @@ -120,32 +125,80 @@ def bullseye_plot(ax, data, vlim=None, segBold=[]):

# Create the fake data
data = np.array(range(17)) + 1
vlim = [data.min(), data.max()]

fig, ax = plt.subplots(figsize=(12, 8), nrows=1, ncols=2,

# 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.canvas.set_window_title('Left Ventricle Bulls Eyes (AHA)')

bullseye_plot(ax[0], data, vlim=vlim)
# 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.
cmap = mpl.cm.jet
norm = mpl.colors.Normalize(vmin=1, vmax=17)

# ColorbarBase derives from ScalarMappable and puts a colorbar
# in a specified axes, so it has everything needed for a
# standalone colorbar. There are many more kwargs, but the
# following gives a basic continuous colorbar with ticks
# and labels.
cb1 = mpl.colorbar.ColorbarBase(axl, cmap=cmap, norm=norm,
orientation='horizontal')
cb1.set_label('Some Units')


# Set the colormap and norm to correspond to the data for which
# the colorbar will be used.
cmap2 = mpl.cm.cool
norm2 = mpl.colors.Normalize(vmin=1, vmax=17)

# ColorbarBase derives from ScalarMappable and puts a colorbar
# in a specified axes, so it has everything needed for a
# standalone colorbar. There are many more kwargs, but the
# following gives a basic continuous colorbar with ticks
# and labels.
cb2 = mpl.colorbar.ColorbarBase(axl2, cmap=cmap2, norm=norm2,
orientation='horizontal')
cb2.set_label('Some other units')

< 8000 /td>

# The second example illustrates the use of a ListedColormap, a
# BoundaryNorm, and extended ends to show the "over" and "under"
# value colors.
cmap3 = mpl.colors.ListedColormap(['r', 'g', 'b', 'c'])
cmap3.set_over('0.35')
cmap3.set_under('0.75')

# If a ListedColormap is used, the length of the bounds array must be
# one greater than the length of the color list. The bounds must be
# monotonically increasing.
bounds = [2, 3, 7, 9, 15]
norm3 = mpl.colors.BoundaryNorm(bounds, cmap3.N)
cb3 = mpl.colorbar.ColorbarBase(axl3, cmap=cmap3, norm=norm3,
# to use 'extend', you must
# specify two extra boundaries:
boundaries=[0]+bounds+[18],
extend='both',
ticks=bounds, # optional
spacing='proportional',
orientation='horizontal')
cb3.set_label('Discrete intervals, some other units')


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

bullseye_plot(ax[1], data, segBold=[3, 5, 6, 11, 12, 16],
vlim=vlim)
ax[1].set_title('Segments [3,5,6,11,12,16] in bold')


#Add legend
cm = plt.cm.jet

#define the bins and normalize
cNorm = mpl.colors.Normalize(vmin=vlim[0], vmax=vlim[1])
bullseye_plot(ax[1], data, cmap=cmap2, norm=norm2)
ax[1].set_title('Bulls Eye (AHA)')

ticks = [vlim[0], 0, vlim[1]]
ax[0] = fig.add_axes([0.2, 0.15, 0.2, 0.05])
cb = mpl.colorbar.ColorbarBase(ax[0], cmap=cm, norm=cNorm, ticks=ticks,
orientation='horizontal')
ax[1] = fig.add_axes([0.62, 0.15, 0.2, 0.05])
cb = mpl.colorbar.ColorbarBase(ax[1], cmap=cm, norm=cNorm, ticks=ticks,
orientation='horizontal')
bullseye_plot(ax[2], data, segBold=[3, 5, 6, 11, 12, 16], cmap=cmap3, norm=norm3)
ax[2].set_title('Segments [3,5,6,11,12,16] in bold')

plt.show()
0