def main(self): self.chartView.SAVE_TEXT.connect(self.save_polar_as_text) self.chartView.SAVE_IMAGE.connect(self.save_polar_as_image) self.chartView.SAVE_SVG.connect(self.save_polar_as_SVG) self.chartView.setRenderHint(QtGui.QPainter.Antialiasing) self.chartView.setContentsMargins(0, 0, 0, 0) if self.type == 'Polar': self.profileChart = QtChart.QPolarChart() elif self.type == 'Normal': self.profileChart = QtChart.QChart() self.profileChart.setBackgroundRoundness(0) self.profileChart.setMargins(QtCore.QMargins(0, 0, 0, 0)) self.profileChart.setTheme(self.theme) self.chartView.setChart(self.profileChart) self.coordinate = QtWidgets.QLabel("") self.chartView.CHART_MOUSE_MOVEMENT.connect(self.update_coordinate) self.chartView.CHART_MOUSE_LEAVE.connect(self.clear_coordinate) self.Grid = QtWidgets.QGridLayout() self.Grid.addWidget(self.chartView, 0, 0) self.Grid.addWidget(self.coordinate, 1, 0) self.setLayout(self.Grid)
def add_chart(self, radius, profile, preset, fontname, fontsize, color, switchXY, kwargs): if self.type == 'Polar': pen1 = QtGui.QPen(QtCore.Qt.SolidLine) pen1.setWidth(3) pen1.setColor(QtGui.QColor(color)) pen2 = QtGui.QPen(QtCore.Qt.DotLine) pen2.setWidth(3) pen2.setColor(QtGui.QColor(color)) if preset == 'IA': Phi1 = profile Phi2 = profile + np.full(len(profile), 180) Radius = radius / np.amax(radius) elif preset == 'FA': Phi1 = profile Phi2 = profile + np.full(len(profile), 180) Radius = radius elif preset == 'general': Phi = profile Radius = radius series1 = QtChart.QLineSeries() series1.setPen(pen1) series2 = QtChart.QLineSeries() series2.setPen(pen2) self.currentRadius = [] self.currentProfile = [] if not switchXY: for x, y in zip(Phi1, Radius): series1.append(x, y) self.currentRadius.append(x) self.currentProfile.append(y) for x, y in zip(Phi2, Radius): series2.append(x, y) self.currentRadius.append(x) self.currentProfile.append(y) else: for y, x in zip(Phi1, Radius): series1.append(x, y) self.currentRadius.append(x) self.currentProfile.append(y) for y, x in zip(Phi2, Radius): series2.append(x, y) self.currentRadius.append(x) self.currentProfile.append(y) self.profileChart = QtChart.QPolarChart() self.profileChart.setTheme(self.theme) self.profileChart.setBackgroundRoundness(0) self.profileChart.setMargins(QtCore.QMargins(0, 0, 0, 0)) self.profileChart.removeAllSeries() self.profileChart.addSeries(series1) self.profileChart.addSeries(series2) self.profileChart.setTitleFont(QtGui.QFont(fontname, fontsize, 57)) self.profileChart.legend().setVisible(False) self.axisR = QtChart.QValueAxis() self.axisR.setTickCount(10) self.axisR.setLabelFormat("%.1f") self.axisR.setLabelsFont(QtGui.QFont(fontname, fontsize, 57)) self.axisR.setTitleFont(QtGui.QFont(fontname, fontsize, 57)) self.axisP = QtChart.QValueAxis() self.axisP.setTickCount(13) self.axisP.setLabelFormat("%.1f") self.axisP.setRange(0, 360) self.axisP.setLabelsFont(QtGui.QFont(fontname, fontsize, 57)) self.axisP.setTitleFont(QtGui.QFont(fontname, fontsize, 57)) if preset == 'IA': z = kwargs['Kp'] low = kwargs['low'] high = kwargs['high'] self.profileChart.setTitle( 'Intensity vs Azimuth at Kperp = {:6.2f} (\u212B\u207B\u00B9)' .format(z)) self.axisR.setTitleText('Intensity (arb. units)') self.axisR.setRange(low, high) elif preset == 'FA': z = kwargs['Kp'] low = kwargs['low'] high = kwargs['high'] self.profileChart.setTitle( 'HWHM vs Azimuth at Kperp = {:6.2f} (\u212B\u207B\u00B9)'. format(z)) self.axisR.setTitleText('HWHM (\u212B\u207B\u00B9)') self.axisR.setRange(low, high) elif preset == 'general': title = kwargs['title'] r_label = kwargs['r_label'] r_unit = kwargs['r_unit'] low = kwargs['low'] high = kwargs['high'] self.profileChart.setTitle(title) self.axisR.setTitleText(r_label + " (" + r_unit + ")") self.axisR.setRange(low, high) self.profileChart.addAxis( self.axisR, QtChart.QPolarChart.PolarOrientationRadial) self.profileChart.addAxis( self.axisP, QtChart.QPolarChart.PolarOrientationAngular) series1.attachAxis(self.axisR) series1.attachAxis(self.axisP) series2.attachAxis(self.axisR) series2.attachAxis(self.axisP) self.chartView.setChart(self.profileChart) self.chartView.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu) self.CHART_IS_PRESENT = True elif self.type == 'Normal': pen = QtGui.QPen(QtCore.Qt.SolidLine) pen.setWidth(3) pen.setColor(QtGui.QColor(color)) series = QtChart.QLineSeries() series.setPen(pen) self.currentRadius = [] self.currentProfile = [] if not switchXY: for x, y in zip(radius, profile): series.append(x, y) self.currentRadius.append(x) self.currentProfile.append(y) else: for y, x in zip(radius, profile): series.append(x, y) self.currentRadius.append(x) self.currentProfile.append(y) self.profileChart = QtChart.QChart() self.profileChart.setTheme(self.theme) self.profileChart.setBackgroundRoundness(0) self.profileChart.setMargins(QtCore.QMargins(0, 0, 0, 0)) self.profileChart.removeAllSeries() self.profileChart.addSeries(series) self.profileChart.setTitleFont(QtGui.QFont(fontname, fontsize, 57)) self.profileChart.legend().setVisible(False) self.axisX = QtChart.QValueAxis() self.axisX.setTickCount(10) self.axisX.setLabelsFont(QtGui.QFont(fontname, fontsize, 57)) self.axisX.setTitleFont(QtGui.QFont(fontname, fontsize, 57)) self.axisY = QtChart.QValueAxis() self.axisY.setTickCount(10) self.axisY.setLabelsFont(QtGui.QFont(fontname, fontsize, 57)) self.axisY.setTitleFont(QtGui.QFont(fontname, fontsize, 57)) if preset == "IK": Az = kwargs['Az'] self.profileChart.setTitle( 'Intensity vs Kperp at \u03C6 = {:5.1f} (\u00BA)'.format( Az)) self.axisX.setTitleText("Intensity (arb. units)") self.axisY.setTitleText("Kperp (\u212B\u207B\u00B9)") elif preset == "FK": Az = kwargs['Az'] self.profileChart.setTitle( 'HWHM vs Kperp at \u03C6 = {:5.1f} (\u00BA)'.format(Az)) self.axisX.setTitleText("HWHM (\u212B\u207B\u00B9)") self.axisY.setTitleText("Kperp (\u212B\u207B\u00B9)") elif preset == "general": title = kwargs['title'] x_label = kwargs['x_label'] x_unit = kwargs['x_unit'] y_label = kwargs['y_label'] y_unit = kwargs['y_unit'] self.profileChart.setTitle(title) self.axisX.setTitleText(x_label + " (" + x_unit + ")") self.axisY.setTitleText(y_label + " (" + y_unit + ")") self.profileChart.addAxis(self.axisX, QtCore.Qt.AlignBottom) self.profileChart.addAxis(self.axisY, QtCore.Qt.AlignLeft) series.attachAxis(self.axisX) series.attachAxis(self.axisY) self.profileChart.legend().setVisible(False) self.chartView.setChart(self.profileChart) self.chartView.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu) self.CHART_IS_PRESENT = True