def animate(timestamp): data_matrix[:, :] = 0.0 for nuclide in timestamp.nuclides: z = pp.find_z(nuclide.element) a = nuclide.isotope value = getattr(nuclide, PROPERTY) if value > 0.0: data_matrix[z, a] = value im.set_array(data_matrix) time_text.set_text("{} s - activity={:.3e} Bq".format( timestamp.cooling_time + timestamp.irradiation_time, timestamp.total_activity)) return [im, time_text]
sm = mpl.cm.ScalarMappable(norm=logcmap, cmap=cmap) sm.set_array([]) fig.colorbar(sm, ax=ax) # iterate over data in the file first times = [] activities = [] data = [] with pp.JSONReader(FILENAME) as output: for timestamp in output: # reset values and colors for _, v in elements.items(): v['rect'].set_facecolor('none') v['value'] = 0.0 for nuclide in timestamp.nuclides: z = pp.find_z(nuclide.element) value = getattr(nuclide, PROPERTY) if value > 0.0: elements[z]['value'] += value elements[z]['rect'].set_facecolor(cmap(logcmap(value))) data.append([(k, v['rect'].get_facecolor()) for k, v in elements.items()]) times.append(timestamp.cooling_time + timestamp.irradiation_time) activities.append(timestamp.total_activity) #then animate def animate(tindx): for entry in data[tindx]: elements[entry[0]]['rect'].set_facecolor(entry[1])
maxZ = max(maxZ, d['Z']) maxA = max(maxA, i) # Create a Rectangle patch # and add the patch to the Axes rect = patches.Rectangle((i - 0.5, d['Z'] - 0.5), 1, 1, linewidth=2, edgecolor='k', facecolor='none') ax.add_patch(rect) # draw notable elements for e in ELEMENTS_OF_INTEREST: z = pp.find_z(e) if z >= Z_RANGE[0] and z <= Z_RANGE[1]: ax.axhline(y=z) ax.text(1, z, e, fontsize=14) # define an empty matrix data_matrix = np.zeros(shape=(maxZ + 1, maxA + 1)) data_matrix[:, :] = 0.0 time_text = ax.text(A_RANGE[0] + 5, Z_RANGE[1], '', fontsize=18) im = plt.imshow(data_matrix, cmap='gnuplot', norm=LogNorm(vmin=MIN_VALUE, vmax=MAX_VALUE)) ax.invert_yaxis() plt.xlabel("A", fontsize=16) plt.ylabel("Z", fontsize=16)