Commit 89a55bdf authored by Erik Asbjørn Mikkelsen Jensen's avatar Erik Asbjørn Mikkelsen Jensen
Browse files

WIP: improved chart of nuclides example

parent 7f978101
......@@ -7,46 +7,92 @@ import matplotlib.pyplot as plt
# chart of nuclides figures, however.
n, Z, N, QECp, QBn, QEC2p, QB2n, QECa, QBa, QECp_est, QBn_est, QEC2p_est, \
QB2n_est, QECa_est, QBa_est, half_life_stbl = np.loadtxt('examples/beta-delayed.dat', unpack=True)
filters = [(half_life_stbl == 1), ((QECp > 0) | (QBn > 0)) & ((QEC2p < 0) | (QB2n < 0)),
((QEC2p > 0) | (QB2n > 0)), ((QECa > 0) | (QBa > 0))]
labels = ['Stable', '$\mathrm{EC\\alpha \ / \ \\beta^{-}\\alpha}$',
'$\mathrm{ECp \ / \ \\beta^{-}n}$',
'$\mathrm{EC2p \ / \ \\beta^{-}2n\ (or\ ECp \ / \ \\beta^{-}n)}$']
rectcenters = [0.5, 0.5, 0.3, 0.3]
rectsizes = [1.0, 1.0, 0.6, 0.6]
linewidths = [0.0, 0.0, 0.0, 0.0]
edgecolors = ['k', 'tomato', 'limegreen', 'dodgerblue', ]
facecolors = ['k', 'tomato', 'limegreen', 'dodgerblue', ]
xmin = np.min(N)
xmax = np.max(N)
ymin = np.min(Z)
ymax = np.max(Z)
QB2n_est, QECa_est, QBa_est, half_life_stbl = np.loadtxt('beta-delayed.dat', unpack=True)
xmin = int(np.min(N))
xmax = int(np.max(N))
ymin = int(np.min(Z))
ymax = int(np.max(Z))
filters = [(np.ones(len(n), dtype=bool)), (half_life_stbl == 1),
(
(
((QECp > 0)) & ((QEC2p < 0) | np.isnan(QEC2p))
) |
(
(QBn > 0) & ((QB2n < 0) | np.isnan(QB2n))
)
),
((QEC2p > 0) | (QB2n > 0)), ((QECa > 0) | (QBa > 0))
]
labels = ['', '$\mathtt{Stable}$',
'$\mathtt{ECp}$ / $\mathtt{\\beta^{-}n}$',
'$\mathtt{EC2p}$ / $\mathtt{\\beta^{-}2n}$',
'$\mathtt{EC\\alpha}$ / $\mathtt{\\beta^{-}\\alpha}$']
rectcenters = [0.5, 0.5, 0.5, 0.5, 0.3]
rectsizes = [1.0, 1.0, 1.0, 1.0, 0.6]
linewidths = [0.0, 0.0, 0.0, 0.0, 0.01]
markersizes = np.array(rectsizes) * 7.0
edgecolors = ['w', 'k', 'tomato', 'limegreen', 'k']
facecolors = ['w', 'k', 'tomato', 'limegreen', 'dodgerblue']
xlower = xupper = ylower = yupper = np.array([])
for i in range(xmin, xmax + 1):
x_indices = np.argwhere(Z == i)
xlower = np.append(xlower, np.max(N[x_indices]))
xupper = np.append(xupper, np.min(N[x_indices]))
for i in range(ymin, ymax + 1):
y_indices = np.argwhere(N == i)
ylower = np.append(ylower, np.min(Z[y_indices]))
yupper = np.append(yupper, np.max(Z[y_indices]))
ax = plt.gca()
ax.set_xticks(np.arange(xmin, xmax + 1, 10))
ax.set_yticks(np.arange(xmin, xmax + 1, 10))
ax.set_xticks(np.arange(xmin, xmax + 1, 5), minor=True)
ax.set_yticks(np.arange(xmin, xmax + 1, 5), minor=True)
ax.set_xticks(np.arange(xmin, xmax + 1, 8))
ax.set_yticks(np.arange(xmin, xmax + 1, 8))
ax.set_xticks(np.arange(xmin, xmax + 1, 4), minor=True)
ax.set_yticks(np.arange(xmin, xmax + 1, 4), minor=True)
ax.set_axisbelow(True)
ax.grid(which='both', linestyle='--', alpha=0.5)
ax.grid(which='both', linestyle='--', alpha=0.3)
for i in range(len(filters)):
plt.plot(-100, -100, marker='s', markeredgecolor=edgecolors[i],
markerfacecolor=facecolors[i], linestyle='', linewidth=linewidths[i], label=labels[i])
if i > 0: # no legend for white squares which are printed for all existing nuclides (otherwise grid is obstructing)
plt.plot(-100, -100, marker='s', markeredgecolor=edgecolors[i], markersize=markersizes[i],
markerfacecolor=facecolors[i], linestyle='', markeredgewidth=linewidths[i], label=labels[i])
for x, y in zip(N[filters[i]], Z[filters[i]]):
ax.add_patch(plt.Rectangle((x - rectcenters[i], y - rectcenters[i]),
rectsizes[i], rectsizes[i], edgecolor=edgecolors[i],
facecolor=facecolors[i], linewidth=linewidths[i]))
ax.set_aspect('equal')
plt.xlim(xmin - 1, xmax + 1)
plt.ylim(xmin - 1, xmax + 1)
# align arrays and fix data-inherent shortcomings
yupper = np.append(yupper, yupper[-1])
yupper = np.roll(yupper, -1)
xupper[0] = 0
xupper[2] = 0
ylower[0] = 0
xlower = np.append(xlower, xlower[-1])
xlower = np.roll(xlower, -1)
plt.vlines(np.array(range(int(xmin), int(xmax) + 1)) + 0.5, ylower - 0.5, yupper[0:-1] + 0.5, lw=0.4, color='k', capstyle='round')
plt.hlines(np.array(range(int(ymin), int(ymax) + 1)) + 0.5, xlower[0:-1] + 0.5, xupper - 0.5, lw=0.4, color='k', capstyle='round')
plt.arrow(3, 17, 6, -5, length_includes_head=True, linewidth=1.0, head_width=0.7, joinstyle='round', facecolor='k')
plt.arrow(7, 21, 2, -8, length_includes_head=True, linewidth=1.0, head_width=0.7, joinstyle='round', edgecolor='darkgray', facecolor='darkgray', zorder=9999)
plt.arrow(10, 21, 1, -6, length_includes_head=True, linewidth=1.0, head_width=0.7, joinstyle='round', edgecolor='darkgray', facecolor='darkgray', zorder=9999)
plt.text(2, 17, '$\mathtt{^{21}Mg}$', horizontalalignment='center', verticalalignment='bottom', fontsize=9.0)
plt.text(6, 21, '$\mathtt{^{22}Al}$', horizontalalignment='center', verticalalignment='bottom', fontsize=9.0, color='darkgray')
plt.text(10, 21, '$\mathtt{^{26}P}$', horizontalalignment='center', verticalalignment='bottom', fontsize=9.0, color='darkgray')
#plt.plot(9, 12, 'o', markerfacecolor="None", markeredgecolor='dimgrey')
#plt.plot(9, 13, 'o', markerfacecolor="None", markeredgecolor='dimgrey')
#plt.plot(11, 15, 'o', markerfacecolor="None", markeredgecolor='dimgrey')
plt.xlim(xmin - 0.5, xmax + 0.5)
plt.ylim(xmin - 0.5, xmax + 0.5)
plt.xlabel('$N$')
plt.ylabel('$Z$')
handles, labels = plt.gca().get_legend_handles_labels() # tak til Ian Hincks: https://stackoverflow.com/questions/22263807/how-is-order-of-items-in-matplotlib-legend-determined\
order = [0, 2, 3, 1]
plt.title('Note: Incomplete figure. See comment in python code.')
plt.legend([handles[idx] for idx in order], [labels[idx] for idx in order])
plt.savefig('examples/beta-delayed.pdf')
handles, labels = plt.gca().get_legend_handles_labels()
order = [0, 1, 2, 3]
L = plt.legend([handles[idx] for idx in order], [labels[idx] for idx in order])
plt.setp(L.texts, family='monospace')
plt.savefig('beta-delayed-asd2.pdf')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment