def get_animation(self, s=300., fs=20., prop_type='real', figsize=None): ''' Get time evolution animation. :param s: Default value 300. Circle size. :param fs: Default value 20. Fontsize. :param figsize: Tuple. Default value None. Figsize. :param prop_type: Default value None. Figsize. :returns: * **ani** -- Animation. ''' error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping') error_handling.positive_real(s, 's') error_handling.positive_real(fs, 'fs') error_handling.prop_type(prop_type) error_handling.tuple_2elem(figsize, 'figsize') if os.name == 'posix': blit = False else: blit = True if prop_type == 'real': color = self.prop.real max_val = max(np.max(color), -np.min(color)) ticks = [-max_val, max_val] cmap = 'seismic' elif prop_type == 'imag': color = self.prop.imag max_val = max(np.max(color), -np.min(color)) ticks = [-max_val, max_val] cmap = 'seismic' else: color = np.abs(self.prop) ** 2 ticks = [0., np.max(color)] cmap = 'Reds' fig, ax = plt.subplots(figsize=figsize) plt.xlim([self.lat.coor['x'][0]-1., self.lat.coor['x'][-1]+1.]) plt.ylim([self.lat.coor['y'][0]-1., self.lat.coor['y'][-1]+1.]) scat = plt.scatter(self.lat.coor['x'], self.lat.coor['y'], c=color[:, 0], s=s, vmin=ticks[0], vmax=ticks[1], cmap=plt.get_cmap(cmap)) frame = plt.gca() frame.axes.get_xaxis().set_ticks([]) frame.axes.get_yaxis().set_ticks([]) ax.set_aspect('equal') if prop_type == 'norm': cbar = fig.colorbar(scat, ticks=ticks) cbar.ax.set_yticklabels(['0','max']) else: cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]]) cbar.ax.set_yticklabels(['min', '0','max']) def update(i, color, scat): scat.set_array(color[:, i]) return scat, ani = animation.FuncAnimation(fig, update, frames=self.steps, fargs=(color, scat), blit=blit, repeat=False) return ani
def intensity_disk(self, intensity, s=200., fs=20., lims=None, figsize=None, title=r'$|\psi|^2$'): ''' Plot the intensity. Colormap with identical disk shape. :param intensity: np.array.Field intensity. :param s: Default value 200. Disk size. :param fs: Default value 20. Font size. :param lims: List. Default value None. Colormap limits. :param figsize: Tuple. Default value None. Figure size. :param title: String. Default value '$|\psi_n|^2$'. Title. :returns: * **fig** -- Figure. ''' error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice') error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites) error_handling.positive_real(s, 's') error_handling.positive_real(fs, 'fs') error_handling.tuple_2elem(figsize, 'figsize') error_handling.string(title, 'title') fig, ax = plt.subplots(figsize=figsize) plt.title(title, fontsize=fs + 5) map_red = plt.get_cmap('Reds') if lims is None: lims = [0., np.max(intensity)] y_ticks = ['0', 'max'] else: y_ticks = lims plt.scatter(self.sys.lat.coor['x'], self.sys.lat.coor['y'], c=intensity, s=s, cmap=map_red, vmin=lims[0], vmax=lims[1]) cbar = plt.colorbar(ticks=lims) ax.set_xticks([]) ax.set_yticks([]) ax.set_xlim( np.min(self.sys.lat.coor['x']) - 1., np.max(self.sys.lat.coor['x']) + 1.) ax.set_ylim( np.min(self.sys.lat.coor['y']) - 1., np.max(self.sys.lat.coor['y']) + 1.) cbar.ax.set_yticklabels([y_ticks[0], y_ticks[1]]) cbar.ax.tick_params(labelsize=fs) ax.set_aspect('equal') fig.set_tight_layout(True) plt.draw() return fig
def lattice_generic(self, coor, ms, lw, c, fs, axis, plt_hop, plt_hop_low, plt_index, figsize): ''' Private method called by *lattice* and *lattice_hop*. ''' error_handling.positive_real(ms, 'ms') error_handling.positive_real(lw, 'lw') error_handling.positive_real(c, 'c') error_handling.positive_real(fs, 'fs') error_handling.boolean(axis, 'axis') error_handling.boolean(plt_hop, 'plt_hop') error_handling.boolean(plt_hop_low, 'plt_hop_low') error_handling.boolean(plt_index, 'plt_index') error_handling.tuple_2elem(figsize, 'figsize') fig, ax = plt.subplots(figsize=figsize) # hoppings if plt_hop: error_handling.empty_ndarray(self.sys.hop, 'sys.hop') self.plt_hopping(coor, self.sys.hop[self.sys.hop['ang'] >= 0], c) if plt_hop_low: error_handling.empty_ndarray(self.sys.hop, 'sys.hop') self.plt_hopping(coor, self.sys.hop[self.sys.hop['ang'] < 0], c) # plot sites for color, tag in zip(self.colors, self.sys.lat.tags): plt.plot(coor['x'][coor['tag'] == tag], coor['y'][coor['tag'] == tag], 'o', color=color, ms=ms, markeredgecolor='none') ax.set_aspect('equal') ax.set_xlim([np.min(coor['x']) - 1., np.max(coor['x']) + 1.]) ax.set_ylim([np.min(coor['y']) - 1., np.max(coor['y']) + 1.]) if not axis: ax.axis('off') # plot indices if plt_index: indices = ['{}'.format(i) for i in range(self.sys.lat.sites)] for l, x, y in zip(indices, coor['x'], coor['y']): plt.annotate(l, xy=(x, y), xytext=(0, 0), textcoords='offset points', ha='right', va='bottom', size=fs) plt.draw() return fig
def intensity_area(self, intensity, s=1000., lw=1., fs=20., plt_hop=False, figsize=None, title=r'$|\psi|^2$'): ''' Plot the intensity. Intensity propotional to disk shape. :param intensity: np.array. Intensity. :param s: Positive Float. Default value 1000. Circle size given by s * intensity. :param lw: Positive Float. Default value 1. Hopping linewidths. :param fs: Positive Float. Default value 20. Fontsize. :param plt_hop: Boolean. Default value False. Plot hoppings. :param figsize: Tuple. Default value None. Figure size. :param title: String. Default value '$|\psi_{ij}|^2$'. Figure title. :returns: * **fig** -- Figure. ''' error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice') error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites) error_handling.positive_real(s, 's') error_handling.positive_real(fs, 'fs') error_handling.boolean(plt_hop, 'plt_hop') error_handling.tuple_2elem(figsize, 'figsize') error_handling.string(title, 'title') fig, ax = plt.subplots() ax.set_xlabel('$i$', fontsize=fs) ax.set_ylabel('$j$', fontsize=fs) ax.set_title(title, fontsize=fs) if plt_hop: plt.plot([self.sys.lat.coor['x'][self.sys.hop['i'][:]], self.sys.lat.coor['x'][self.sys.hop['j'][:]]], [self.sys.lat.coor['y'][self.sys.hop['i'][:]], self.sys.lat.coor['y'][self.sys.hop['j'][:]]], 'k', lw=lw) for tag, color in zip(self.sys.lat.tags, self.colors): plt.scatter(self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == tag], self.sys.lat.coor['y'][self.sys.lat.coor['tag'] == tag], s=100*s*intensity[self.sys.lat.coor['tag'] == tag], c=color, alpha=0.5) ax.set_aspect('equal') ax.axis('off') x_lim = [np.min(self.sys.lat.coor['x'])-2., np.max(self.sys.lat.coor['x'])+2.] y_lim = [np.min(self.sys.lat.coor['y'])-2., np.max(self.sys.lat.coor['y'])+2.] ax.set_xlim(x_lim) ax.set_ylim(y_lim) fig.set_tight_layout(True) plt.draw() return fig
def plt_propagation_1d(self, prop_type="real", fs=20, figsize=None): """ Plot time evolution for 1D systems. :param fs: Default value 20. Fontsize. """ error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping") error_handling.positive_real(fs, "fs") error_handling.prop_type(prop_type) error_handling.tuple_2elem(figsize, "figsize") fig, ax = plt.subplots(figsize=figsize) plt.ylabel("n", fontsize=fs) plt.xlabel("z", fontsize=fs) if prop_type == "real": color = self.prop_smooth_1d(self.prop.real) max_val = max(np.max(color), -np.min(color)) ticks = [-max_val, max_val] cmap = "seismic" elif prop_type == "imag": color = self.prop_smooth_1d(self.prop.imag) max_val = max(np.max(color), -np.min(color)) ticks = [-max_val, max_val] cmap = "seismic" else: color = self.prop_smooth_1d(np.abs(self.prop) ** 2) ticks = [0.0, np.max(color[:, -1])] cmap = plt.cm.hot extent = (-0, self.steps * self.dz, self.lat.sites - 0.5, -0.5) aspect = "auto" interpolation = "nearest" im = plt.imshow( color, cmap=cmap, aspect=aspect, interpolation=interpolation, extent=extent, vmin=ticks[0], vmax=ticks[-1] ) for label in ax.xaxis.get_majorticklabels(): label.set_fontsize(fs) for label in ax.yaxis.get_majorticklabels(): label.set_fontsize(fs) ax.get_yaxis().set_major_locator(plt.MaxNLocator(integer=True)) if prop_type == "norm": cbar = fig.colorbar(im, ticks=ticks) cbar.ax.set_yticklabels(["0", "max"]) else: cbar = fig.colorbar(im, ticks=[ticks[0], 0, ticks[1]]) cbar.ax.set_yticklabels(["min", "0", "max"]) cbar.ax.tick_params(labelsize=fs) return fig
def plt_propagation_1d(self, prop_type='real', fs=20, figsize=None): ''' Plot time evolution for 1D systems. :param fs: Default value 20. Fontsize. ''' error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping') error_handling.positive_real(fs, 'fs') error_handling.prop_type(prop_type) error_handling.tuple_2elem(figsize, 'figsize') fig, ax = plt.subplots(figsize=figsize) plt.ylabel('n', fontsize=fs) plt.xlabel('z', fontsize=fs) if prop_type == 'real': color = self.prop_smooth_1d(self.prop.real) max_val = max(np.max(color), -np.min(color)) ticks = [-max_val, max_val] cmap = 'seismic' elif prop_type == 'imag': color = self.prop_smooth_1d(self.prop.imag) max_val = max(np.max(color), -np.min(color)) ticks = [-max_val, max_val] cmap = 'seismic' else: color = self.prop_smooth_1d(np.abs(self.prop) ** 2) ticks = [0., np.max(color[:, -1])] cmap = plt.cm.hot extent = (-0, self.steps*self.dz, self.lat.sites-.5, -.5) aspect = 'auto' interpolation = 'nearest' im = plt.imshow(color, cmap=cmap, aspect=aspect, interpolation=interpolation, extent=extent, vmin=ticks[0], vmax=ticks[-1]) for label in ax.xaxis.get_majorticklabels(): label.set_fontsize(fs) for label in ax.yaxis.get_majorticklabels(): label.set_fontsize(fs) ax.get_yaxis().set_major_locator(plt.MaxNLocator(integer=True)) if prop_type == 'norm': cbar = fig.colorbar(im, ticks=ticks) cbar.ax.set_yticklabels(['0','max']) else: cbar = fig.colorbar(im, ticks=[ticks[0], 0, ticks[1]]) cbar.ax.set_yticklabels(['min', '0','max']) cbar.ax.tick_params(labelsize=fs) return fig
def intensity_disk(self, intensity, s=200., fs=20., lims=None, figsize=None, title=r'$|\psi|^2$'): ''' Plot the intensity. Colormap with identical disk shape. :param intensity: np.array.Field intensity. :param s: Default value 200. Disk size. :param fs: Default value 20. Font size. :param lims: List. Default value None. Colormap limits. :param figsize: Tuple. Default value None. Figure size. :param title: String. Default value '$|\psi_n|^2$'. Title. :returns: * **fig** -- Figure. ''' error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice') error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites) error_handling.positive_real(s, 's') error_handling.positive_real(fs, 'fs') error_handling.tuple_2elem(figsize, 'figsize') error_handling.string(title, 'title') fig, ax = plt.subplots(figsize=figsize) plt.title(title, fontsize=fs+5) map_red = plt.get_cmap('Reds') if lims is None: lims = [0., np.max(intensity)] y_ticks = ['0', 'max'] else: y_ticks = lims plt.scatter(self.sys.lat.coor['x'], self.sys.lat.coor['y'], c=intensity, s=s, cmap=map_red, vmin=lims[0], vmax=lims[1]) cbar = plt.colorbar(ticks=lims) ax.set_xticks([]) ax.set_yticks([]) ax.set_xlim(np.min(self.sys.lat.coor['x'])-1., np.max(self.sys.lat.coor['x'])+1.) ax.set_ylim(np.min(self.sys.lat.coor['y'])-1., np.max(self.sys.lat.coor['y'])+1.) cbar.ax.set_yticklabels([y_ticks[0], y_ticks[1]]) cbar.ax.tick_params(labelsize=fs) ax.set_aspect('equal') fig.set_tight_layout(True) plt.draw() return fig
def lattice_generic(self, coor, ms, lw, c, fs, axis, plt_hop, plt_hop_low, plt_index, figsize): ''' Private method called by *lattice* and *lattice_hop*. ''' error_handling.positive_real(ms, 'ms') error_handling.positive_real(lw, 'lw') error_handling.positive_real(c, 'c') error_handling.positive_real(fs, 'fs') error_handling.boolean(axis, 'axis') error_handling.boolean(plt_hop, 'plt_hop') error_handling.boolean(plt_hop_low, 'plt_hop_low') error_handling.boolean(plt_index, 'plt_index') error_handling.tuple_2elem(figsize, 'figsize') fig, ax = plt.subplots(figsize=figsize) # hoppings if plt_hop: error_handling.empty_ndarray(self.sys.hop, 'sys.hop') self.plt_hopping(coor, self.sys.hop[self.sys.hop['ang']>=0], c) if plt_hop_low: error_handling.empty_ndarray(self.sys.hop, 'sys.hop') self.plt_hopping(coor, self.sys.hop[self.sys.hop['ang']<0], c) # plot sites for color, tag in zip(self.colors, self.sys.lat.tags): plt.plot(coor['x'][coor['tag'] == tag], coor['y'][coor['tag'] == tag], 'o', color=color, ms=ms, markeredgecolor='none') ax.set_aspect('equal') ax.set_xlim([np.min(coor['x'])-1., np.max(coor['x'])+1.]) ax.set_ylim([np.min(coor['y'])-1., np.max(coor['y'])+1.]) if not axis: ax.axis('off') # plot indices if plt_index: indices = ['{}'.format(i) for i in range(self.sys.lat.sites)] for l, x, y in zip(indices, coor['x'], coor['y']): plt.annotate(l, xy=(x, y), xytext=(0, 0), textcoords='offset points', ha='right', va='bottom', size=fs) plt.draw() return fig
def intensity_area(self, intensity, s=1000., lw=1., fs=20., plt_hop=False, figsize=None, title=r'$|\psi|^2$'): ''' Plot the intensity. Intensity propotional to disk shape. :param intensity: np.array. Intensity. :param s: Positive Float. Default value 1000. Circle size given by s * intensity. :param lw: Positive Float. Default value 1. Hopping linewidths. :param fs: Positive Float. Default value 20. Fontsize. :param plt_hop: Boolean. Default value False. Plot hoppings. :param figsize: Tuple. Default value None. Figure size. :param title: String. Default value '$|\psi_{ij}|^2$'. Figure title. :returns: * **fig** -- Figure. ''' error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice') error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites) error_handling.positive_real(s, 's') error_handling.positive_real(fs, 'fs') error_handling.boolean(plt_hop, 'plt_hop') error_handling.tuple_2elem(figsize, 'figsize') error_handling.string(title, 'title') fig, ax = plt.subplots() ax.set_xlabel('$i$', fontsize=fs) ax.set_ylabel('$j$', fontsize=fs) ax.set_title(title, fontsize=fs) if plt_hop: plt.plot([ self.sys.lat.coor['x'][self.sys.hop['i'][:]], self.sys.lat.coor['x'][self.sys.hop['j'][:]] ], [ self.sys.lat.coor['y'][self.sys.hop['i'][:]], self.sys.lat.coor['y'][self.sys.hop['j'][:]] ], 'k', lw=lw) for tag, color in zip(self.sys.lat.tags, self.colors): plt.scatter( self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == tag], self.sys.lat.coor['y'][self.sys.lat.coor['tag'] == tag], s=100 * s * intensity[self.sys.lat.coor['tag'] == tag], c=color, alpha=0.5) ax.set_aspect('equal') ax.axis('off') x_lim = [ np.min(self.sys.lat.coor['x']) - 2., np.max(self.sys.lat.coor['x']) + 2. ] y_lim = [ np.min(self.sys.lat.coor['y']) - 2., np.max(self.sys.lat.coor['y']) + 2. ] ax.set_xlim(x_lim) ax.set_ylim(y_lim) fig.set_tight_layout(True) plt.draw() return fig
def get_animation_nb(self, s=300.0, fs=20.0, prop_type="real", figsize=None): """ Get time evolution animation for iPython notebooks. :param s: Default value 300. Circle shape. :param fs: Default value 20. Fontsize. :returns: * **ani** -- Animation. """ """ Get time evolution animation. :param s: Default value 300. Circle size. :param fs: Default value 20. Fontsize. :param figsize: Tuple. Default value None. Figsize. :param prop_type: Default value None. Figsize. :returns: * **ani** -- Animation. """ error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping") error_handling.positive_real(s, "s") error_handling.positive_real(fs, "fs") error_handling.prop_type(prop_type) error_handling.tuple_2elem(figsize, "figsize") if prop_type == "real" or prop_type == "imag": color = self.prop.real max_val = max(np.max(color[:, -1]), -np.min(color[:, -1])) ticks = [-max_val, max_val] cmap = "seismic" else: color = np.abs(self.prop) ** 2 ticks = [0.0, np.max(color)] cmap = "Reds" fig = plt.figure() ax = plt.axes( xlim=(np.min(self.lat.coor["x"] - 0.5), np.max(self.lat.coor["x"] + 0.5)), ylim=(np.min(self.lat.coor["y"] - 0.5), np.max(self.lat.coor["y"] + 0.5)), ) ax.set_aspect("equal") frame = plt.gca() frame.axes.get_xaxis().set_ticks([]) frame.axes.get_yaxis().set_ticks([]) scat = plt.scatter( self.lat.coor["x"], self.lat.coor["y"], c=color[:, 0], s=s, vmin=ticks[0], vmax=ticks[1], cmap=cmap ) if prop_type == "real" or prop_type == "imag": cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]]) cbar.ax.set_yticklabels(["min", "0", "max"]) else: cbar = fig.colorbar(scat, ticks=[0, ticks[1]]) cbar.ax.set_yticklabels(["0", "max"]) def init(): scat.set_array(color[:, 0]) return (scat,) def animate(i): scat.set_array(color[:, i]) return (scat,) return animation.FuncAnimation(fig, animate, init_func=init, frames=self.steps, interval=120, blit=True)
def get_animation(self, s=300.0, fs=20.0, prop_type="real", figsize=None): """ Get time evolution animation. :param s: Default value 300. Circle size. :param fs: Default value 20. Fontsize. :param figsize: Tuple. Default value None. Figsize. :param prop_type: Default value None. Figsize. :returns: * **ani** -- Animation. """ error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping") error_handling.positive_real(s, "s") error_handling.positive_real(fs, "fs") error_handling.prop_type(prop_type) error_handling.tuple_2elem(figsize, "figsize") if os.name == "posix": blit = False else: blit = True if prop_type == "real": color = self.prop.real max_val = max(np.max(color), -np.min(color)) ticks = [-max_val, max_val] cmap = "seismic" elif prop_type == "imag": color = self.prop.imag max_val = max(np.max(color), -np.min(color)) ticks = [-max_val, max_val] cmap = "seismic" else: color = np.abs(self.prop) ** 2 ticks = [0.0, np.max(color)] cmap = "Reds" fig, ax = plt.subplots(figsize=figsize) plt.xlim([self.lat.coor["x"][0] - 1.0, self.lat.coor["x"][-1] + 1.0]) plt.ylim([self.lat.coor["y"][0] - 1.0, self.lat.coor["y"][-1] + 1.0]) scat = plt.scatter( self.lat.coor["x"], self.lat.coor["y"], c=color[:, 0], s=s, vmin=ticks[0], vmax=ticks[1], cmap=plt.get_cmap(cmap), ) frame = plt.gca() frame.axes.get_xaxis().set_ticks([]) frame.axes.get_yaxis().set_ticks([]) ax.set_aspect("equal") if prop_type == "norm": cbar = fig.colorbar(scat, ticks=ticks) cbar.ax.set_yticklabels(["0", "max"]) else: cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]]) cbar.ax.set_yticklabels(["min", "0", "max"]) def update(i, color, scat): scat.set_array(color[:, i]) return (scat,) ani = animation.FuncAnimation(fig, update, frames=self.steps, fargs=(color, scat), blit=blit, repeat=False) return ani
def get_animation_nb(self, s=300., fs=20., prop_type='real', figsize=None): ''' Get time evolution animation for iPython notebooks. :param s: Default value 300. Circle shape. :param fs: Default value 20. Fontsize. :returns: * **ani** -- Animation. ''' ''' Get time evolution animation. :param s: Default value 300. Circle size. :param fs: Default value 20. Fontsize. :param figsize: Tuple. Default value None. Figsize. :param prop_type: Default value None. Figsize. :returns: * **ani** -- Animation. ''' error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping') error_handling.positive_real(s, 's') error_handling.positive_real(fs, 'fs') error_handling.prop_type(prop_type) error_handling.tuple_2elem(figsize, 'figsize') if prop_type == 'real' or prop_type == 'imag': color = self.prop.real max_val = max(np.max(color[:, -1]), -np.min(color[:, -1])) ticks = [-max_val, max_val] cmap = 'seismic' else: color = np.abs(self.prop) ** 2 ticks = [0., np.max(color)] cmap = 'Reds' fig = plt.figure() ax = plt.axes(xlim=(np.min(self.lat.coor['x']-.5), np.max(self.lat.coor['x']+.5)), ylim=(np.min(self.lat.coor['y']-.5), np.max(self.lat.coor['y']+.5))) ax.set_aspect('equal') frame = plt.gca() frame.axes.get_xaxis().set_ticks([]) frame.axes.get_yaxis().set_ticks([]) scat = plt.scatter(self.lat.coor['x'], self.lat.coor['y'], c=color[:, 0], s=s, vmin=ticks[0], vmax=ticks[1], cmap=cmap) if prop_type == 'real' or prop_type == 'imag': cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]]) cbar.ax.set_yticklabels(['min', '0','max']) else: cbar = fig.colorbar(scat, ticks=[0, ticks[1]]) cbar.ax.set_yticklabels(['0','max']) def init(): scat.set_array(color[:, 0]) return scat, def animate(i): scat.set_array(color[:, i]) return scat, return animation.FuncAnimation(fig, animate, init_func=init, frames=self.steps, interval=120, blit=True)