def __init__(self, title: str = None, parent: QtWidgets.QWidget = None): super().__init__(QtCharts.QChart(), theme=light_theme, parent=parent) self.setRubberBand(QtCharts.QChartView.RectangleRubberBand) self.setMinimumSize(QtCore.QSize(640, 480)) self.setRenderHint(QtGui.QPainter.Antialiasing) if title is not None: self.chart().setTitle(title) self.chart().legend().hide() self.xaxis = QtCharts.QValueAxis() self.yaxis = QtCharts.QValueAxis() self.addAxis(self.xaxis, QtCore.Qt.AlignBottom) self.addAxis(self.yaxis, QtCore.Qt.AlignLeft) self.label_series = QtCharts.QScatterSeries() self.label_series.append(0, 0) self.label_series.setBrush( QtGui.QBrush(QtCore.Qt.black, QtCore.Qt.NoBrush)) self.label_series.setPointLabelsFormat("(@xPoint, @yPoint)") self.label_series.setPointLabelsColor(light_theme["text"]) self.label_series.setVisible(False) self.chart().addSeries(self.label_series) self.label_series.attachAxis(self.xaxis) self.label_series.attachAxis(self.yaxis) self.line = QtCharts.QLineSeries() self.line.setPen(QtGui.QPen(sequential[1], 1.5)) # self.line.setColor(QtCore.Qt.red) self.chart().addSeries(self.line) self.line.attachAxis(self.xaxis) self.line.attachAxis(self.yaxis) self.series = QtCharts.QScatterSeries() self.series.setPen(QtGui.QPen(sequential[1], 1.5)) self.series.setBrush(QtGui.QBrush(highlights[1])) self.series.setMarkerSize(12) self.chart().addSeries(self.series) self.series.attachAxis(self.xaxis) self.series.attachAxis(self.yaxis) self.series.hovered.connect(self.showPointPosition) self.label = QtWidgets.QGraphicsTextItem() self.label.setPlainText("hats") self.label.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations) self.chart().scene().addItem(self.label) self.chart().plotAreaChanged.connect(self.moveLabel)
def createScatterChart(data): chart = QtCharts.QChart() # chart.legend().hide() chart.setTitle("Spline chart (market shares)") series0 = QtCharts.QScatterSeries() series0.setName("height / weight") series0.setMarkerShape(QtCharts.QScatterSeries.MarkerShapeCircle) series0.setMarkerSize(5.0) #series0.append([0, 6, 6, 4]) pointsList = list( map(lambda hw: QPointF(hw[0], hw[1]), zip(data[0], data[1]))) series0.append(pointsList) chartView = QtCharts.QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) chart.addSeries(series0) chart.setTitle("Nba Players active as of 2018 height/weight") chart.createDefaultAxes() chart.setDropShadowEnabled(False) chart.axes(Qt.Vertical)[0].setTitleText("Weight") chart.axes(Qt.Horizontal)[0].setTitleText("Height") return chartView
def __init__(self, parent=None, f=None, *args, **kwargs): QtWidgets.QWidget.__init__(self) self.maxSize = 31 # 只存储最新的31个数据 self.maxX = 300 self.maxY = 100 self.data = [] #折线 self.splineSeries = QtCharts.QSplineSeries() #离散点 self.scatterSeries = QtCharts.QScatterSeries() self.scatterSeries.setMarkerSize(8) self.chart = QtCharts.QChart() self.chart.addSeries(self.splineSeries) self.chart.addSeries(self.scatterSeries) self.chart.legend().hide() self.chart.setTitle("实时动态曲线") self.chart.createDefaultAxes() self.chart.axisX().setRange(0, self.maxX) self.chart.axisY().setRange(0, self.maxY) self.chartView = QtCharts.QChartView(self.chart) #self.chartView.setRenderHint(QtGui.QPainter.Antialiasing) layout = QtWidgets.QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.chartView) self.setLayout(layout) self.thread=None
def __init__(self, parent=None): super().__init__() self.reader = FsaReader() self.treewidget = QTreeWidget() self.channel_view = qtc.QChartView() self.regression_view = qtc.QChartView() # setup tree self.treewidget.setColumnCount(2) self.treewidget.setHeaderLabels(["Rox size", "predicted"]) self.channel_view.setChart(qtc.QChart()) self.regression_view.setChart(qtc.QChart()) self.channel_serie = qtc.QLineSeries() self.regression_serie = qtc.QScatterSeries() self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.channel_view.setChart(qtc.QChart()) self.regression_view.setChart(qtc.QChart()) v_splitter = QSplitter(Qt.Vertical) v_splitter.addWidget(self.regression_view) v_splitter.addWidget(self.channel_view) h_splitter = QSplitter(Qt.Horizontal) h_splitter.addWidget(self.treewidget) h_splitter.addWidget(v_splitter) v_layout = QVBoxLayout() v_layout.addWidget(h_splitter) v_layout.addWidget(self.buttons) self.setLayout(v_layout)
def __init__(self, parent: QtWidgets.QGraphicsItem = None): super().__init__(parent) self.setMinimumSize(640, 320) self.xaxis = QtCharts.QValueAxis() self.xaxis.setGridLineVisible(False) self.xaxis.rangeChanged.connect(self.updateYRange) self.xaxis.setLabelsVisible(False) self.yaxis = QtCharts.QValueAxis() self.yaxis.setGridLineVisible(False) self.yaxis.setLabelFormat("%.2g") self.yaxis.setTitleText("Response") self.addAxis(self.xaxis, QtCore.Qt.AlignBottom) self.addAxis(self.yaxis, QtCore.Qt.AlignLeft) self.yvalues: np.ndarray = None self.series = QtCharts.QLineSeries() self.series.setPen(QtGui.QPen(QtCore.Qt.black, 1.0)) self.series.setUseOpenGL(True) # Speed for many line? self.addSeries(self.series) self.series.attachAxis(self.xaxis) self.series.attachAxis(self.yaxis) self.scatter_series = QtCharts.QScatterSeries() self.scatter_series.setMarkerSize(5) self.scatter_series.setColor(QtCore.Qt.red) self.scatter_series.setUseOpenGL(True) self.addSeries(self.scatter_series) self.scatter_series.attachAxis(self.xaxis) self.scatter_series.attachAxis(self.yaxis) self.ub = QtCharts.QLineSeries() self.lc = QtCharts.QLineSeries() self.ld = QtCharts.QLineSeries() for series, color, label in zip( [self.ub, self.lc, self.ld], [QtGui.QColor(255, 0, 0), QtGui.QColor(0, 255, 0), QtGui.QColor(0, 0, 255)], ["μb", "Lc", "Ld"], ): series.setPen(QtGui.QPen(color, 1.0, QtCore.Qt.DashLine)) series.setName(label) series.setUseOpenGL(True) self.addSeries(series) series.attachAxis(self.xaxis) series.attachAxis(self.yaxis) self.vlines: List[QtCharts.QLineSeries] = [] # Clean legend self.legend().setMarkerShape(QtCharts.QLegend.MarkerShapeFromSeries) self.legend().markers(self.series)[0].setVisible(False) self.legend().markers(self.scatter_series)[0].setVisible(False)
def plot_series(self, name, data, new): # Create QLineSeries if self.series is None: self.series = QtCharts.QScatterSeries() self.series.setName(name) # Filling QLineSeries for p in data: self.series.append(*p) if new: self.q_chart.addSeries(self.series) self.series.attachAxis(self.axis_x) self.series.attachAxis(self.axis_y)
def plot_channel(self, channel): self.channel_serie.clear() self.channel_view.chart().removeAllSeries() self.channel_serie.setName("Size Marker") for x, y in self.reader.normalize_data(channel): self.channel_serie.append(x, y) # Display peaks self.peaks_serie = qtc.QScatterSeries() for i, peak in enumerate(self.reader.peaks): self.peaks_serie.append(self.reader.transform(peak), 1000) self.channel_view.chart().addSeries(self.channel_serie) self.channel_view.chart().addSeries(self.peaks_serie) self.channel_view.chart().createDefaultAxes()
def create_scatterchart(self): chart = QtCharts.QChart() chart.setTitle("Scatter chart") name = "Series " for i, lst in enumerate(self.data_table): series = QtCharts.QScatterSeries(chart) for data in lst: series.append(data[0]) series.setName("{}{}".format(name, i)) chart.addSeries(series) chart.createDefaultAxes() chart.axisX().setRange(0, self.value_max) chart.axisY().setRange(0, self.value_count) # Add space to label to add space between labels and axis chart.axisY().setLabelFormat("%.1f ") return chart
def __init__(self, title: str = None, parent: QtWidgets.QWidget = None): super().__init__(QtCharts.QChart(), theme=light_theme, parent=parent) self.setRubberBand(QtCharts.QChartView.RectangleRubberBand) self.setMinimumSize(QtCore.QSize(640, 480)) self.setRenderHint(QtGui.QPainter.Antialiasing) if title is not None: self.chart().setTitle(title) self.chart().legend().hide() self.xaxis = QtCharts.QValueAxis() self.xaxis.setRange(0.0, 1.0) self.yaxis = QtCharts.QValueAxis() self.yaxis.setRange(0.0, 1.0) self.addAxis(self.xaxis, QtCore.Qt.AlignBottom) self.addAxis(self.yaxis, QtCore.Qt.AlignLeft) self.scatter = QtCharts.QScatterSeries() self.scatter.setColor(sequential[1]) self.scatter.setMarkerSize(5) self.scatter.setUseOpenGL(True) self.chart().addSeries(self.scatter) self.scatter.attachAxis(self.xaxis) self.scatter.attachAxis(self.yaxis) self.line = QtCharts.QLineSeries() self.line.setPen(QtGui.QPen(QtCore.Qt.black, 1.5)) self.chart().addSeries(self.line) self.line.attachAxis(self.xaxis) self.line.attachAxis(self.yaxis) self.t1 = QtCharts.QLineSeries() self.t1.setPen(QtGui.QPen(QtCore.Qt.black, 1.0, QtCore.Qt.DashLine)) self.chart().addSeries(self.t1) self.t1.attachAxis(self.xaxis) self.t1.attachAxis(self.yaxis) self.t2 = QtCharts.QLineSeries() self.t2.setPen(QtGui.QPen(QtCore.Qt.black, 1.0, QtCore.Qt.DashLine)) self.chart().addSeries(self.t2) self.t2.attachAxis(self.xaxis) self.t2.attachAxis(self.yaxis)
def addScatterSeries( self, name: str, ys: np.ndarray, xs: np.ndarray = None, color: QtGui.QColor = QtCore.Qt.black, markersize: float = 10.0, label: str = None, ) -> None: """Add a scatter plot to the chart. Args: name: key for series ys: y data xs: x data, defaults is range(ys.size) color: color of markers markersize: size of markers label: optional label in legend """ series = QtCharts.QScatterSeries() self.chart().addSeries(series) series.setColor(color) series.setPen(QtGui.QPen(color, 1.0)) series.setBrush(QtGui.QBrush(color)) series.setMarkerSize(markersize) series.setUseOpenGL(True) # Speed for many line? if label is not None: series.setName(label) else: self.chart().legend().markers(series)[0].setVisible(False) series.attachAxis(self.xaxis) series.attachAxis(self.yaxis) self.series[name] = series self.setSeries(name, ys, xs=xs)
def copyChart(chart: QtCharts.QChart) -> QtCharts.QChart: """ Return a copy of the chart """ newChart = QtCharts.QChart() # Copy axes axes = chart.axes() for axis in axes: newChart.addAxis(copyAxis(newChart, axis), axis.alignment()) # Copy series allSeries: List[QtCharts.QAbstractSeries] = chart.series() for s in allSeries: # Create new series with same points, dependent on actual type s_copy: QtCharts.QAbstractSeries if isinstance(s, QtCharts.QScatterSeries): s_copy = QtCharts.QScatterSeries() s_copy.append(s.points()) elif isinstance(s, QtCharts.QLineSeries): s_copy = QtCharts.QLineSeries() s_copy.append(s.points()) elif isinstance(s, QtCharts.QAbstractBarSeries): # Note: this is not used s_copy = QtCharts.QBarSeries() for bar in s.barSets(): bar_copy = QtCharts.QBarSet(bar.label()) s_copy.append(bar_copy) else: raise NotImplementedError('Cannot copy series of type {}'.format( type(s))) s_copy.setName(s.name()) # Add series to chart newChart.addSeries(s_copy) # Add axis to series s_copy.attachAxis(newChart.axisX()) s_copy.attachAxis(newChart.axisY()) if chart.title(): newChart.setTitle(chart.title()) return newChart
def __init__(self, parent=None): super(NetworkGraph, self).__init__(parent) self.setScene(QGraphicsScene(self)) self.setDragMode(QGraphicsView.NoDrag) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) #self.setFrameShape(QFrame.NoFrame) # Chart self._chart = QtCharts.QChart() self._chart.setBackgroundRoundness(0) self._chart.setMargins(QMargins( -28, -9, -11, -23)) # make sure the graphing area fills the whole chart view # self._chart.zoom(0.1) self._chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations) self._chart.setTheme(QtCharts.QChart.ChartThemeDark) #self._chart.setMinimumSize(340, 280) #self._chart.setTitle("Hover the line to show callout. Click the line to make it stay") self._chart.legend().hide() # Series 1 self.series = QtCharts.QLineSeries() self.series.append(1, 3) self.series.append(4, 5) self.series.append(6, 2) self._chart.addSeries(self.series) # Series 2 self.series2 = QtCharts.QLineSeries() self.series2.append(4, 5) self.series2.append(5, 6) self._chart.addSeries(self.series2) # Scatter self.seriesS = QtCharts.QScatterSeries() self.seriesS.setMarkerShape(QtCharts.QScatterSeries.MarkerShapeCircle) self.seriesS.append(1, 3) self.seriesS.append(4, 5) self.seriesS.append(5, 6) self.seriesS.append(6, 2) self._chart.addSeries(self.seriesS) # Create axes and config grid invisible self._chart.createDefaultAxes() self.axes = self._chart.axes() for axis in self.axes: axis.setLabelsVisible(False) axis.setGridLineVisible(False) axis.setLineVisible(False) self._chart.setAcceptHoverEvents(True) # Add to scene self.setRenderHint(QPainter.Antialiasing) self.scene().addItem(self._chart) # Callout setup self._callouts = [] self._tooltip = Callout(self._chart) self.series.clicked.connect(self.keepCallout) self.series.hovered.connect(self.tooltip) self.series2.clicked.connect(self.keepCallout) self.series2.hovered.connect(self.tooltip) self.setMouseTracking(True)
def __init__(self, chart): QObject.__init__(self) self.module_path = os.path.dirname(__file__) self.pca_matrix = np.array([]) self.labels = [] self.chart = chart self.model = Model() self.model_selection = Model() self.callout = Callout(self.chart) self.callout.hide() loader = QUiLoader() self.main_widget = loader.load(self.module_path + "/ui/table.ui") self.table_view = self.main_widget.findChild(QTableView, "table_view") table_cfg_frame = self.main_widget.findChild(QFrame, "table_cfg_frame") pc_frame = self.main_widget.findChild(QFrame, "pc_frame") button_load_data = self.main_widget.findChild(QPushButton, "button_load_data") self.pc1_variance_ratio = self.main_widget.findChild( QLabel, "pc1_variance_ratio") self.pc1_singular_value = self.main_widget.findChild( QLabel, "pc1_singular_value") self.pc2_variance_ratio = self.main_widget.findChild( QLabel, "pc2_variance_ratio") self.pc2_singular_value = self.main_widget.findChild( QLabel, "pc2_singular_value") self.legend = self.main_widget.findChild(QLineEdit, "legend_name") self.groupbox_axis = self.main_widget.findChild( QGroupBox, "groupbox_axis") self.groupbox_norm = self.main_widget.findChild( QGroupBox, "groupbox_norm") self.preprocessing_none = self.main_widget.findChild( QRadioButton, "radio_none") self.preprocessing_normalize = self.main_widget.findChild( QRadioButton, "radio_normalize") self.preprocessing_standardize = self.main_widget.findChild( QRadioButton, "radio_standardize") self.preprocessing_axis_features = self.main_widget.findChild( QRadioButton, "radio_axis_features") self.preprocessing_axis_samples = self.main_widget.findChild( QRadioButton, "radio_axis_samples") self.preprocessing_norm_l1 = self.main_widget.findChild( QRadioButton, "radio_norm_l1") self.preprocessing_norm_l2 = self.main_widget.findChild( QRadioButton, "radio_norm_l2") self.preprocessing_norm_max = self.main_widget.findChild( QRadioButton, "radio_norm_max") self.progressbar = self.main_widget.findChild(QProgressBar, "progressbar") self.progressbar.hide() self.table_view.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeToContents) self.table_view.verticalHeader().setSectionResizeMode( QHeaderView.ResizeToContents) self.table_view.setModel(self.model) # chart series self.series = QtCharts.QScatterSeries(self.table_view) self.series.setName("table") self.series.setMarkerSize(15) self.series.hovered.connect(self.on_hover) self.chart.addSeries(self.series) self.mapper = QtCharts.QVXYModelMapper() self.mapper.setXColumn(1) self.mapper.setYColumn(2) self.mapper.setSeries(self.series) self.mapper.setModel(self.model) # selection series self.series_selection = QtCharts.QScatterSeries(self.table_view) self.series_selection.setName("selection") self.series_selection.setMarkerShape( QtCharts.QScatterSeries.MarkerShapeRectangle) self.series_selection.setMarkerSize(15) self.series_selection.hovered.connect(self.on_hover) self.chart.addSeries(self.series_selection) self.mapper_selection = QtCharts.QVXYModelMapper() self.mapper_selection.setXColumn(1) self.mapper_selection.setYColumn(2) self.mapper_selection.setSeries(self.series_selection) self.mapper_selection.setModel(self.model_selection) # effects button_load_data.setGraphicsEffect(self.button_shadow()) table_cfg_frame.setGraphicsEffect(self.card_shadow()) pc_frame.setGraphicsEffect(self.card_shadow()) # signals button_load_data.clicked.connect(self.open_file) self.table_view.selectionModel().selectionChanged.connect( self.selection_changed) self.legend.returnPressed.connect(self.update_legend) self.preprocessing_none.toggled.connect(self.on_preprocessing_changed) self.preprocessing_normalize.toggled.connect( self.on_preprocessing_changed) self.preprocessing_standardize.toggled.connect( self.on_preprocessing_changed) self.preprocessing_axis_features.toggled.connect( self.on_preprocessing_axis_changed) self.preprocessing_axis_samples.toggled.connect( self.on_preprocessing_axis_changed) self.preprocessing_norm_l1.toggled.connect( self.on_preprocessing_norm_changed) self.preprocessing_norm_l2.toggled.connect( self.on_preprocessing_norm_changed) self.preprocessing_norm_max.toggled.connect( self.on_preprocessing_norm_changed) # event filter self.table_view.installEventFilter(self)
from PySide2.QtGui import ( QColor, QPainter, QPainterPath, QImage, ) from PySide2.QtWidgets import (QApplication, QMainWindow) from PySide2.QtCharts import QtCharts import math if __name__ == "__main__": app = QApplication(sys.argv) chart = QtCharts.QChart() series0 = QtCharts.QScatterSeries() series0.setName("scatter1") series0.setMarkerShape(QtCharts.QScatterSeries.MarkerShapeCircle) series0.setMarkerSize(15.0) series1 = QtCharts.QScatterSeries() series1.setName("scatter2") series1.setMarkerShape(QtCharts.QScatterSeries.MarkerShapeRectangle) series1.setMarkerSize(20.0) series2 = QtCharts.QScatterSeries() series2.setName("scatter3") series2.setMarkerShape(QtCharts.QScatterSeries.MarkerShapeRectangle) series2.setMarkerSize(30.0) series0.append(0, 6)
def initUI(self): dataY = [ 9.030, 8.810, 9.402, 8.664, 8.773, 8.774, 8.416, 9.101, 8.687, 8.767 ] seriesList = [] series1 = QtCharts.QLineSeries() seriesList.append(series1) series2 = QtCharts.QScatterSeries() seriesList.append(series2) for i in range(len(dataY)): for series in seriesList: series.append(i + 1, dataY[i]) series1.setColor(QtGui.QColor('blue')) series2.setColor(QtGui.QColor('gray')) chart = QtCharts.QChart() for series in seriesList: chart.addSeries(series) chart.setTitle('SPC Chart Example') chart.setBackgroundBrush(QtGui.QColor("ivory")) chart.legend().hide() axisX = QtCharts.QValueAxis() axisX.setLinePenColor('gray') axisX.setTickCount(len(dataY) + 2) axisX.setRange(0, len(dataY) + 1) axisX.setLabelFormat('%d') axisX2 = QtCharts.QValueAxis() axisX2.setLinePenColor('gray') axisX2.setRange(0, len(dataY) + 1) axisX2.setLabelFormat(' ') ymax = max(dataY) ymin = min(dataY) yrange = ymax - ymin ydelta = yrange * 0.05 axisY = QtCharts.QValueAxis() axisY.setLinePenColor('gray') axisY.setRange(ymin - ydelta, ymax + ydelta) axisY2 = QtCharts.QValueAxis() axisY2.setLinePenColor('gray') axisY2.setRange(ymin - ydelta, ymax + ydelta) chart.addAxis(axisX, QtCore.Qt.AlignBottom) chart.addAxis(axisX2, QtCore.Qt.AlignTop) chart.addAxis(axisY, QtCore.Qt.AlignLeft) chart.addAxis(axisY2, QtCore.Qt.AlignRight) for series in seriesList: # chart.setAxisX(axisX, series) # chart.setAxisY(axisY, series) series.attachAxis(axisX) series.attachAxis(axisY) chartView = QtCharts.QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) layout = QVBoxLayout() layout.addWidget(chartView) self.setLayout(layout) self.resize(600, 400)
from PySide2.QtWidgets import (QApplication, QMainWindow) from PySide2.QtCharts import QtCharts import math import ddv.csv if __name__ == "__main__": app = QApplication(sys.argv) data = ddv.csv.getScatterChartData("nba_player_data.csv") chart = QtCharts.QChart() series0 = QtCharts.QScatterSeries() series0.setName("height / weight") series0.setMarkerShape(QtCharts.QScatterSeries.MarkerShapeCircle) series0.setMarkerSize(5.0) #series0.append([0, 6, 6, 4]) pointsList = list(map(lambda hw: QPointF(hw[0], hw[1]), zip(data[0], data[1]))) series0.append(pointsList) chartView = QtCharts.QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) chart.addSeries(series0)