def plot_slices(self): # remove all slice patches for i in range(len(self.mplWidget.axes.patches))[::-1]: patch = self.mplWidget.axes.patches[i] if patch.get_label() == "Slice": patch.remove() axes = self.comboBox_plt.currentText() # for overlays alpha = 0.3 colors = ("r", "b", "g") # add scan area to xy plot patches = [] labels = [] if axes == "xy": x_min = float(self.lineEdit_scan_x_min.text()) x_max = float(self.lineEdit_scan_x_max.text()) y_min = float(self.lineEdit_scan_y_min.text()) y_max = float(self.lineEdit_scan_y_max.text()) rectangle = Rectangle( (x_min, y_min), x_max - x_min, y_max - y_min, color="r", alpha=alpha, ec="k", label="Slice", ) self.mplWidget.axes.add_patch(rectangle) patches.append(rectangle) labels.append("Scan Area") self.mplWidget.axes.legend(patches, labels) # plot multislice layers elif axes == "xz" or axes == "yz": positions = self.atoms.get_positions() if axes == "xz": x_min = float(self.lineEdit_scan_x_min.text()) x_max = float(self.lineEdit_scan_x_max.text()) z_min = positions[:, 2].min() z_max = positions[:, 2].max() if axes == "yz": x_min = float(self.lineEdit_scan_y_min.text()) x_max = float(self.lineEdit_scan_y_max.text()) z_min = positions[:, 2].min() z_max = positions[:, 2].max() # in Angstrom slice_thickness = float(self.lineEdit_slice_thickness.text()) # from stemCL code nslices = math.ceil((z_max - z_min) / slice_thickness) patches = [] labels = [] for i in range(nslices): rectangle = Rectangle( (x_min, z_min + slice_thickness * i), x_max - x_min, slice_thickness, color=colors[i % len(colors)], alpha=alpha, ec="k", label="Slice", ) self.mplWidget.axes.add_patch(rectangle) self.mplWidget.axes.text( self.mplWidget.axes.get_xlim()[0], z_min + slice_thickness * i, str(i), size=12, color=rectangle.get_facecolor(), bbox=dict(boxstyle="round", color="w", alpha=0.5), ha="left", va="bottom", ) patches.append(rectangle) labels.append(f"Slice {i}") self.mplWidget.draw()