From a425953dc987ae20f97f86a82de6fd345443763d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ariel=20Hern=C3=A1n=20Curiale?= Date: Mon, 15 Sep 2014 10:53:40 +0200 Subject: [PATCH 1/5] Left ventricle bull eye In this example we create the bull eye representation for the left ventricle according to the American Heart Association (AHA) --- .../pylab_examples/leftventricle_bulleye.py | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 examples/pylab_examples/leftventricle_bulleye.py diff --git a/examples/pylab_examples/leftventricle_bulleye.py b/examples/pylab_examples/leftventricle_bulleye.py new file mode 100644 index 000000000000..3db144889632 --- /dev/null +++ b/examples/pylab_examples/leftventricle_bulleye.py @@ -0,0 +1,115 @@ +def bulleye_plot(data, ax=None, figsize=(12,8), vlim=None, segBold=[]): + """ + Left Ventricle bull eye for the Left Ventricle according to the + American Heart Association (AHA) + Use Example: + data = range(17) + bulleye_plot(data) + """ + data = np.array(data).ravel() + + if vlim is None: + vlim = [data.min(), data.max()] + + axnone = False + if ax is None: + fig, ax = plt.subplots(figsize=figsize, subplot_kw=dict(projection='polar')) + fig.canvas.set_window_title('Left Ventricle Bull Eyes (AHA)') + axnone = True + + + theta = np.linspace(0, 2*np.pi, 768) + r = np.linspace(0.2, 1, 4) + + + # Create the bound for the segment 17 + linewidth = 2 + for i in range(r.shape[0]): + ax.plot(theta, np.repeat(r[i], theta.shape), '-k', lw=linewidth) + + # Create the bounds for the segments 1-12 + for i in range(6): + theta_i = i * 60 * np.pi/180 + ax.plot([theta_i, theta_i], [r[1], 1], '-k', lw=linewidth) + + # Create the bounds for the segmentss 13-16 + for i in range(4): + theta_i = i * 90 * np.pi/180 - 45*np.pi/180 + ax.plot([theta_i, theta_i], [r[0], r[1]], '-k', lw=linewidth) + + + + + + # Fill the segments 1-6 + r0 = r[2:4] + r0 = np.repeat(r0[:,np.newaxis], 128, axis=1).T + for i in range(6): + theta0 = theta[i*128:i*128+128] + 60*np.pi/180 # First segment start at 60 degrees + 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]) + 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) + ax.plot(theta0[-1], [r[2],r[3]], '-k', lw=linewidth+1) + + # Fill the segments 7-12 + r0 = r[1:3] + r0 = np.repeat(r0[:,np.newaxis], 128, axis=1).T + for i in range(6): + theta0 = theta[i*128:i*128+128] + 60*np.pi/180 # First segment start at 60 degrees + 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]) + 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) + ax.plot(theta0[-1], [r[1],r[2]], '-k', lw=linewidth+1) + + + # Fill the segments 13-16 + r0 = r[0:2] + r0 = np.repeat(r0[:,np.newaxis], 192, axis=1).T + for i in range(4): + theta0 = theta[i*192:i*192+192] + 45*np.pi/180 # First segment start at 45 degrees + 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]) + 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) + ax.plot(theta0[-1], [r[0],r[1]], '-k', lw=linewidth+1) + + #Fill the segments 17 + if data.size == 17: + r0 = np.array([0, r[0]]) + 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]) + if 17 in segBold: + ax.plot(theta0, r0, '-k', lw=linewidth+2) + + + ax.set_ylim([0, 1]) + ax.set_yticklabels([]) + ax.set_xticklabels([]) + + + #Add legend + if axnone: + cm = plt.cm.jet + + #define the bins and normalize + cNorm = mpl.colors.Normalize(vmin=vlim[0], vmax=vlim[1]) + + ax = fig.add_axes([0.3, 0.04, 0.45, 0.05]) + ticks = [vlim[0], 0, vlim[1]] + cb = mpl.colorbar.ColorbarBase(ax, cmap=cm, norm=cNorm, + orientation='horizontal', ticks=ticks) + + plt.show() + + if axnone: + return fig, ax From ce918847ad70c2c9e37b0ec756a7c9325457448c Mon Sep 17 00:00:00 2001 From: curiale Date: Mon, 15 Sep 2014 16:22:01 +0200 Subject: [PATCH 2/5] Style corrections --- .../pylab_examples/leftventricle_bulleye.py | 123 ++++++++++-------- 1 file changed, 68 insertions(+), 55 deletions(-) diff --git a/examples/pylab_examples/leftventricle_bulleye.py b/examples/pylab_examples/leftventricle_bulleye.py index 3db144889632..30e7dfba6cb6 100644 --- a/examples/pylab_examples/leftventricle_bulleye.py +++ b/examples/pylab_examples/leftventricle_bulleye.py @@ -1,115 +1,128 @@ -def bulleye_plot(data, ax=None, figsize=(12,8), vlim=None, segBold=[]): +#!/usr/bin/env python +""" +In this example we create the bull eye representation for the left ventricle +according to the American Heart Association (AHA) +""" + +import numpy as np +import matplotlib as mpl +import matplotlib.pyplot as plt + + +def bulleye_plot(data, ax, vlim=None, segBold=[]): """ - Left Ventricle bull eye for the Left Ventricle according to the + Left Ventricle bull eye for the Left Ventricle according to the American Heart Association (AHA) - Use Example: - data = range(17) - bulleye_plot(data) """ + + linewidth = 2 data = np.array(data).ravel() if vlim is None: vlim = [data.min(), data.max()] - axnone = False - if ax is None: - fig, ax = plt.subplots(figsize=figsize, subplot_kw=dict(projection='polar')) - fig.canvas.set_window_title('Left Ventricle Bull Eyes (AHA)') - axnone = True - - theta = np.linspace(0, 2*np.pi, 768) r = np.linspace(0.2, 1, 4) - # Create the bound for the segment 17 - linewidth = 2 for i in range(r.shape[0]): ax.plot(theta, np.repeat(r[i], theta.shape), '-k', lw=linewidth) # Create the bounds for the segments 1-12 for i in range(6): - theta_i = i * 60 * np.pi/180 + theta_i = i*60*np.pi/180 ax.plot([theta_i, theta_i], [r[1], 1], '-k', lw=linewidth) # Create the bounds for the segmentss 13-16 for i in range(4): - theta_i = i * 90 * np.pi/180 - 45*np.pi/180 + theta_i = i*90*np.pi/180 - 45*np.pi/180 ax.plot([theta_i, theta_i], [r[0], r[1]], '-k', lw=linewidth) - - - - # Fill the segments 1-6 r0 = r[2:4] - r0 = np.repeat(r0[:,np.newaxis], 128, axis=1).T + r0 = np.repeat(r0[:, np.newaxis], 128, axis=1).T for i in range(6): - theta0 = theta[i*128:i*128+128] + 60*np.pi/180 # First segment start at 60 degrees - theta0 = np.repeat(theta0[:,np.newaxis], 2, axis=1) - z = np.ones((128,2)) * data[i] + # First segment start at 60 degrees + 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]) 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) - ax.plot(theta0[-1], [r[2],r[3]], '-k', lw=linewidth+1) + ax.plot(theta0[0], [r[2], r[3]], '-k', lw=linewidth+1) + ax.plot(theta0[-1], [r[2], r[3]], '-k', lw=linewidth+1) # Fill the segments 7-12 r0 = r[1:3] - r0 = np.repeat(r0[:,np.newaxis], 128, axis=1).T + r0 = np.repeat(r0[:, np.newaxis], 128, axis=1).T for i in range(6): - theta0 = theta[i*128:i*128+128] + 60*np.pi/180 # First segment start at 60 degrees - theta0 = np.repeat(theta0[:,np.newaxis], 2, axis=1) - z = np.ones((128,2)) * data[i+6] + # First segment start at 60 degrees + 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]) 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) - ax.plot(theta0[-1], [r[1],r[2]], '-k', lw=linewidth+1) - + ax.plot(theta0[0], [r[1], r[2]], '-k', lw=linewidth+1) + ax.plot(theta0[-1], [r[1], r[2]], '-k', lw=linewidth+1) # Fill the segments 13-16 r0 = r[0:2] - r0 = np.repeat(r0[:,np.newaxis], 192, axis=1).T + r0 = np.repeat(r0[:, np.newaxis], 192, axis=1).T for i in range(4): - theta0 = theta[i*192:i*192+192] + 45*np.pi/180 # First segment start at 45 degrees - theta0 = np.repeat(theta0[:,np.newaxis], 2, axis=1) - z = np.ones((192,2)) * data[i+12] + # First segment start at 45 degrees + 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]) 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) - ax.plot(theta0[-1], [r[0],r[1]], '-k', lw=linewidth+1) + ax.plot(theta0[0], [r[0], r[1]], '-k', lw=linewidth+1) + ax.plot(theta0[-1], [r[0], r[1]], '-k', lw=linewidth+1) #Fill the segments 17 if data.size == 17: r0 = np.array([0, r[0]]) - 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] + 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]) if 17 in segBold: ax.plot(theta0, r0, '-k', lw=linewidth+2) - ax.set_ylim([0, 1]) ax.set_yticklabels([]) ax.set_xticklabels([]) - #Add legend - if axnone: - cm = plt.cm.jet +# 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, + subplot_kw=dict(projection='polar')) +fig.canvas.set_window_title('Left Ventricle Bull Eyes (AHA)') + +bulleye_plot(data, ax[0], vlim=vlim) +ax[0].set_title('Bull Eye (AHA)') + +bulleye_plot(data, ax[1], segBold=[3,5,6,11,12,16], + vlim=vlim) +ax[1].set_title('Segments [3,5,6,11,12,16] in bold') + - #define the bins and normalize - cNorm = mpl.colors.Normalize(vmin=vlim[0], vmax=vlim[1]) +#Add legend +cm = plt.cm.jet - ax = fig.add_axes([0.3, 0.04, 0.45, 0.05]) - ticks = [vlim[0], 0, vlim[1]] - cb = mpl.colorbar.ColorbarBase(ax, cmap=cm, norm=cNorm, - orientation='horizontal', ticks=ticks) +#define the bins and normalize +cNorm = mpl.colors.Normalize(vmin=vlim[0], vmax=vlim[1]) - plt.show() +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') - if axnone: - return fig, ax +plt.show() From 45cef157aac1bfd154788108aeba0c79e4383425 Mon Sep 17 00:00:00 2001 From: curiale Date: Fri, 3 Oct 2014 15:55:19 +0200 Subject: [PATCH 3/5] Improve the documentation --- .../pylab_examples/leftventricle_bulleye.py | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/examples/pylab_examples/leftventricle_bulleye.py b/examples/pylab_examples/leftventricle_bulleye.py index 30e7dfba6cb6..af330ed3ba74 100644 --- a/examples/pylab_examples/leftventricle_bulleye.py +++ b/examples/pylab_examples/leftventricle_bulleye.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -In this example we create the bull eye representation for the left ventricle -according to the American Heart Association (AHA) +This example demonstrates how to create the 17 segment model for the left +ventricle recommended by the American Heart Association (AHA). """ import numpy as np @@ -9,10 +9,33 @@ import matplotlib.pyplot as plt -def bulleye_plot(data, ax, vlim=None, segBold=[]): +def bullseye_plot(ax, data, vlim=None, segBold=[]): """ - Left Ventricle bull eye for the Left Ventricle according to the - American Heart Association (AHA) + Bullseye representation for the left ventricle. + + Parameters + ---------- + 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 + segBold: list of int + A list with the segments to highlight + + + Notes + ----- + This function create the 17 segment model for the left ventricle according + to the American Heart Association (AHA) [1]_ + + References + ---------- + .. [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. 539–542, 2002. """ linewidth = 2 @@ -101,13 +124,13 @@ def bulleye_plot(data, ax, vlim=None, segBold=[]): fig, ax = plt.subplots(figsize=(12, 8), nrows=1, ncols=2, subplot_kw=dict(projection='polar')) -fig.canvas.set_window_title('Left Ventricle Bull Eyes (AHA)') +fig.canvas.set_window_title('Left Ventricle Bulls Eyes (AHA)') -bulleye_plot(data, ax[0], vlim=vlim) -ax[0].set_title('Bull Eye (AHA)') +bullseye_plot(ax[0], data, vlim=vlim) +ax[0].set_title('Bulls Eye (AHA)') -bulleye_plot(data, ax[1], segBold=[3,5,6,11,12,16], - vlim=vlim) +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') From 0709202aeff9eacd88880f7b3962933fd030b328 Mon Sep 17 00:00:00 2001 From: curiale Date: Sat, 18 Oct 2014 13:41:07 +0200 Subject: [PATCH 4/5] Added the colormap and normalize as arguments --- .gitignore | 2 + .../pylab_examples/leftventricle_bulleye.py | 117 +++++++++++++----- 2 files changed, 87 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 6db5a64dc88e..086a399a96b5 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ examples/tests/* !examples/tests/backend_driver.py texput.log result_images + +*.swp diff --git a/examples/pylab_examples/leftventricle_bulleye.py b/examples/pylab_examples/leftventricle_bulleye.py index af330ed3ba74..e90791b12a65 100644 --- a/examples/pylab_examples/leftventricle_bulleye.py +++ b/examples/pylab_examples/leftventricle_bulleye.py @@ -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. @@ -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 @@ -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. 539–542, 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() - 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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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') + + +# 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() From 1b831cbb3201ed3291610749a7d8cb74d0bef2e2 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 22 Jun 2015 21:44:12 -0400 Subject: [PATCH 5/5] MNT: minor doc + convention clean up - no mutables as default values - match doc order to arg order - pep8 clean up --- .../pylab_examples/leftventricle_bulleye.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/pylab_examples/leftventricle_bulleye.py b/examples/pylab_examples/leftventricle_bulleye.py index e90791b12a65..889d7d1e9658 100644 --- a/examples/pylab_examples/leftventricle_bulleye.py +++ b/examples/pylab_examples/leftventricle_bulleye.py @@ -9,7 +9,7 @@ import matplotlib.pyplot as plt -def bullseye_plot(ax, data, segBold=[], cmap=None, norm=None): +def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None): """ Bullseye representation for the left ventricle. @@ -18,12 +18,12 @@ def bullseye_plot(ax, data, segBold=[], cmap=None, norm=None): ax : axes data : list of int and float The intensity values for each of the 17 segments - 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 + segBold: list of int, optional A list with the segments to highlight + cmap : ColorMap or None, optional + Optional argument to set the desired colormap + norm : Normalize or None, optional + Optional argument to normalize data into the [0.0, 1.0] range Notes @@ -35,10 +35,12 @@ def bullseye_plot(ax, data, segBold=[], cmap=None, norm=None): ---------- .. [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. 539-542, 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. """ + if segBold is None: + segBold = [] linewidth = 2 data = np.array(data).ravel() @@ -108,7 +110,7 @@ def bullseye_plot(ax, data, segBold=[], cmap=None, norm=None): ax.plot(theta0[0], [r[0], r[1]], '-k', lw=linewidth+1) ax.plot(theta0[-1], [r[0], r[1]], '-k', lw=linewidth+1) - #Fill the segments 17 + # Fill the segments 17 if data.size == 17: r0 = np.array([0, r[0]]) r0 = np.repeat(r0[:, np.newaxis], theta.size, axis=1).T @@ -198,7 +200,8 @@ def bullseye_plot(ax, data, segBold=[], cmap=None, norm=None): bullseye_plot(ax[1], data, cmap=cmap2, norm=norm2) ax[1].set_title('Bulls Eye (AHA)') -bullseye_plot(ax[2], data, segBold=[3, 5, 6, 11, 12, 16], cmap=cmap3, norm=norm3) +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()