8000 Doc AHA bullseye by tacaswell · Pull Request #4550 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Doc AHA bullseye #4550

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 5 commits into from
Jun 23, 2015
Merged
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
Next Next commit
Style corrections
  • Loading branch information
curiale committed Sep 15, 2014
commit ce918847ad70c2c9e37b0ec756a7c9325457448c
123 changes: 68 additions & 55 deletions examples/pylab_examples/leftventricle_bulleye.py
Original file line number Diff line number Diff line change
@@ -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()
0