1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
| import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt
def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None): """ Bullseye representation for the left ventricle.
Parameters ---------- ax : axes data : list of int and float The intensity values for each of the 17 segments 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 ----- 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. """ if segBold is None: segBold = []
linewidth = 2 data = np.array(data).ravel()
if cmap is None: cmap = plt.cm.viridis
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)
for i in range(r.shape[0]): ax.plot(theta, np.repeat(r[i], theta.shape), '-k', lw=linewidth)
for i in range(6): theta_i = np.deg2rad(i * 60) ax.plot([theta_i, theta_i], [r[1], 1], '-k', lw=linewidth)
for i in range(4): theta_i = np.deg2rad(i * 90 - 45) ax.plot([theta_i, theta_i], [r[0], r[1]], '-k', lw=linewidth)
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] + np.deg2rad(60) theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1) z = np.ones((128, 2)) * data[i] 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) ax.plot(theta0[-1], [r[2], r[3]], '-k', lw=linewidth + 1)
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] + np.deg2rad(60) theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1) z = np.ones((128, 2)) * data[i + 6] 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) ax.plot(theta0[-1], [r[1], r[2]], '-k', lw=linewidth + 1)
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] + np.deg2rad(45) theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1) z = np.ones((192, 2)) * data[i + 12] 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) ax.plot(theta0[-1], [r[0], r[1]], '-k', lw=linewidth + 1)
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, cmap=cmap, norm=norm) if 17 in segBold: ax.plot(theta0, r0, '-k', lw=linewidth + 2)
ax.set_ylim([0, 1]) ax.set_yticklabels([]) ax.set_xticklabels([])
data = np.array(range(17)) + 1
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)')
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])
cmap = mpl.cm.viridis norm = mpl.colors.Normalize(vmin=1, vmax=17)
cb1 = mpl.colorbar.ColorbarBase(axl, cmap=cmap, norm=norm, orientation='horizontal') cb1.set_label('Some Units')
cmap2 = mpl.cm.cool norm2 = mpl.colors.Normalize(vmin=1, vmax=17)
cb2 = mpl.colorbar.ColorbarBase(axl2, cmap=cmap2, norm=norm2, orientation='horizontal') cb2.set_label('Some other units')
cmap3 = mpl.colors.ListedColormap(['r', 'g', 'b', 'c']) cmap3.set_over('0.35') cmap3.set_under('0.75')
bounds = [2, 3, 7, 9, 15] norm3 = mpl.colors.BoundaryNorm(bounds, cmap3.N) cb3 = mpl.colorbar.ColorbarBase(axl3, cmap=cmap3, norm=norm3, boundaries=[0] + bounds + [18], extend='both', ticks=bounds, spacing='proportional', orientation='horizontal') cb3.set_label('Discrete intervals, some other units')
bullseye_plot(ax[0], data, cmap=cmap, norm=norm) ax[0].set_title('Bulls Eye (AHA)')
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) ax[2].set_title('Segments [3,5,6,11,12,16] in bold')
plt.show()
|