def row_clicked(self, item): """ method for accessing row in table_view """ pen_1 = mkPen(color="#69a8de", style=Qt.DotLine, width=2) pen_2 = mkPen(color="#d2e5f5", style=Qt.DotLine, width=2) bar_item = BarGraphItem(x=self.x, height=self.y, width=self.width, brush="#d2e5f5") chart_item = PlotDataItem(x=self.x, y=self.y, pen=pen_1, symbol='+', symbolSize=14) clear_line = PlotDataItem(x=self.x, y=self.y, pen=pen_2, symbol='+', symbolSize=14) if item.row() < len(self.x): row = len(self.x) - 1 - item.row() if self.reverse else item.row() clicked_item = BarGraphItem(x=[self.x[row]], height=self.y[row], width=self.width, brush="#69a8de") self.graphics_view.addItem(bar_item) self.graphics_view.addItem(clicked_item) self.graphics_view.addItem(chart_item) else: self.graphics_view.addItem(bar_item) self.graphics_view.addItem(clear_line)
def highlight_bar_items(self, x_val_1, y_val_1, x_val_2, y_val_2): """ method for highlighting bar items """ self.plot_widget_1.removeItem(self.bar_item_1) self.plot_widget_2.removeItem(self.bar_item_2) self.bar_item_1 = BarGraphItem(x=[x_val_1], height=y_val_1, width=self.width, brush="#69a8de") self.bar_item_2 = BarGraphItem(x=[x_val_2], height=y_val_2, width=self.width, brush="#69a8de") self.plot_widget_1.addItem(self.bar_item_1) self.plot_widget_2.addItem(self.bar_item_2)
def getBarPlotItem(self, scheduledPhase, color): barplot = BarGraphItem( x=[ -self.context.cyclenameToIndex(scheduledPhase.componentName, scheduledPhase.cycleName, scheduledPhase.name) ], height=[(scheduledPhase.scheduledEndDT - scheduledPhase.scheduledStartDT) / 60], y0=(scheduledPhase.scheduledStartDT - self.actualTime) / 60, width=0.6, brush=color) barplot.rotate(-90) return barplot
def __init__(self, channels=list(), xLabels=list(), yLabel='', title=''): """Init.""" super().__init__() self._channels = list() for chn in channels: self._channels.append(_ConnSignal(chn)) self._xLabels = xLabels self._yLabel = yLabel self.showGrid(x=True, y=True) self.setBackground('w') self.setXRange(min=-0.5, max=len(xLabels)-0.5) self.setTitle(title) self.setLabel('left', text=self._yLabel) self.getAxis('left').setStyle( autoExpandTextSpace=False, tickTextWidth=30) self.getAxis('bottom').setTicks( [[(i, l) for i, l in enumerate(self._xLabels)]]) self._baritems = dict() for idx, lbl in enumerate(self._xLabels): baritem = BarGraphItem( x=[idx, ], width=1, height=0, brush='b') self.addItem(baritem) self._baritems[idx] = baritem self._timer = QTimer() self._timer.timeout.connect(self._update_graph) self._timer.setInterval(500) # ms self._timer.start()
def highlight_bar_items(self, x_val, y_val): """ method for highlighting bar items """ self.graphics_view.removeItem(self.bar_item_2) self.bar_item_2 = BarGraphItem(x=[x_val], height=y_val, width=self.width, brush="#69a8de") self.graphics_view.addItem(self.bar_item_2)
def bar(self, x: Optional[np.ndarray], y: np.ndarray, label: Optional[str] = None, width: float = 1, orientation: Orientation = Orientation.Vertical, **kwargs) -> None: kwargs = Axes._add_label_to_kwargs(label, kwargs) x = Axes._create_x(y) if x is None else x if orientation == Orientation.Vertical: self._raw.addItem( BarGraphItem(x=x, height=y, width=width, **kwargs)) else: raise NotImplementedError
def __init__(self, x: list, y: list, graphics_view: PlotWidget, labels: str, units=None, x_labels=None, width=0.4): """ Constructor / Instantiation of class Parameters ---------- x : list x-values y : list y-values graphics_view : PlotWidget widget to add items labels : str legend labels units : tuple measurement units for tuple width : int, float width of any bars x_labels : array-like array of dates, i.e. time-period """ super().__init__() Assertor.assert_data_types([x, y, graphics_view, labels, units, x_labels, width], [list, list, PlotWidget, str, (type(None), tuple), (type(None), list), (float, int)]) self.x = asarray(arange(1, len(x) + 1, 1)) self.y = asarray([float(val.replace(" ", "").replace("%", "")) if val else 0 for val in y]) self.graphics_view = graphics_view self.labels = labels self.units = units if units else tuple(["" for _ in range(10)]) self.x_time = x_labels self.width = width self.bar_item_1 = BarGraphItem(x=self.x, height=self.y, width=self.width, brush="#a8ccec") self.graphics_view.addItem(self.bar_item_1) self.bar_item_2 = None self.label = TextItem() pen = mkPen(color="#4c96d7", style=Qt.SolidLine, width=1) self.vertical_line = InfiniteLine(angle=90, movable=False, pen=pen) self.graphics_view.addItem(self.vertical_line) self.view_box = self.graphics_view.getViewBox() self.configure_cross_hair() self.graphics_view.plotItem.vb.setLimits(xMin=0, xMax=max(self.x) + 1) self.graphics_view.setMenuEnabled(False)
def update_graph(self, dataDict): try: # emptyDict = { # "x": [], # "y": [] # } if self.plotDict["BarGraphItem"] is not None: self.plotDict["plotItem"].removeItem( self.plotDict["BarGraphItem"]) # if distributionType is None: # self.plotDict["plotDataItem"].setData(**dataDict) # else: # self.plotDict["plotDataItem"].setData(**emptyDict) self.plotDict["BarGraphItem"] = BarGraphItem(x=dataDict["x"], height=dataDict["y"], width=0.4, brush='r') self.plotDict["plotItem"].addItem(self.plotDict["BarGraphItem"]) except Exception as E: log.error(E)
def stacked_bar(self, x: Optional[np.ndarray], y: np.ndarray, label: Optional[str] = None, width: float = 1, orientation: Orientation = Orientation.Vertical, **kwargs) -> None: x = Axes._create_x(y) if x is None else x accumulated: np.ndarray = np.zeros(y.shape[1], dtype=float) kwargs = Axes._add_label_to_kwargs(label, kwargs) for i in range(0, y.shape[0]): if orientation == Orientation.Vertical: self._raw.addItem( BarGraphItem(x=x, y=accumulated + y[i, :] / 2, height=y[i, :], width=width, **kwargs)) else: raise NotImplementedError accumulated += y[i, :]
def __init__(self, x: list, y: list, graphics_view: PlotWidget, table_view: QTableView, legend: str = "", width=0.5, reverse=True): """ Constructor / Instantiation of class Parameters ---------- x : list x-values y : list y-values graphics_view : PlotWidget graphics view to place chart table_view : QTableView table view to link graphics_view legend : HTML str legend width : int, float width of bars reverse : bool reverse selection in table """ Assertor.assert_data_types( [x, y, graphics_view, table_view, legend, width], [list, list, PlotWidget, QTableView, str, (int, float)]) super().__init__() self.x = x self.y = y self.graphics_view = graphics_view self.table_view = table_view self.label = TextItem() self.width = width self.reverse = reverse place = percentile(insert(array(self.x), 0, 0), 2) self.label.setPos(place, int(max(y) * 1.5)) self.label.setHtml(legend) self.graphics_view.addItem(self.label, ignore_bounds=True) self.bar_item = BarGraphItem(x=self.x, height=self.y, width=self.width, brush="#d2e5f5") self.graphics_view.addItem(self.bar_item) pen = mkPen(color="#d2e5f5", style=Qt.DotLine, width=2) self.graphics_view.plot(x=self.x, y=self.y, pen=pen, symbol='+', symbolSize=14) self.graphics_view.plotItem.vb.setLimits(xMin=min(self.x) - width, xMax=max(self.x) + width) self.graphics_view.setMenuEnabled(False) self.graphics_view.getViewBox().enableAutoRange()
def __init__(self, x_1: list, y_1: list, x_2: list, y_2: list, x_3: list, y_3: list, graphics_view_1: PlotWidget, graphics_view_2: PlotWidget, labels: tuple, units: tuple, width=0.4): Assertor.assert_data_types( [x_1, y_1, x_2, y_2, graphics_view_1, graphics_view_2, width], [list, list, list, list, PlotWidget, PlotWidget, (int, float)]) super().__init__() """ Constructor / Instantiation of class Parameters ---------- x_1 : list x-values y_1 : list y-values x_2 : list x-values y_2 : list y-values x_3 : list x-values y_3 : list y-values graphics_view_1 : PlotWidget graphics view to place chart graphics_view_2 : PlotWidget graphics view to place chart labels : tuple labels to be used in chart units : tuple measurement units width : int, float width of any bars """ self.x_1 = list(arange(1, len(x_1) + 1, 1)) self.y_1 = y_1 self.x_2 = self.x_1 self.y_2 = y_2 self.x_3 = x_3 self.y_3 = y_3 self.graphics_view_1 = graphics_view_1 self.graphics_view_2 = graphics_view_2 self.bar_item_1 = BarGraphItem(x=self.x_1, height=self.y_1, width=width, brush="#a8ccec") self.graphics_view_1.addItem(self.bar_item_1) self.bar_item_2 = BarGraphItem(x=self.x_1, height=self.y_2, width=width, brush="#d2e5f5") self.graphics_view_1.addItem(self.bar_item_2) self.bar_item_3 = BarGraphItem(x=self.x_1, height=self.y_3, width=width, brush="#a8ccec") self.graphics_view_2.addItem(self.bar_item_3) self.bar_item_4 = BarGraphItem(x=self.x_1, height=cumsum(self.y_2), width=width, brush="#d2e5f5") self.graphics_view_2.addItem(self.bar_item_4) self.cross_hair = DoubleCrossHair(asarray(self.x_1), asarray(self.y_1), asarray(self.x_2), asarray(self.y_3), self.graphics_view_1, self.graphics_view_2, labels, units=units, width=width, x_labels=x_1) self.graphics_view_1.plotItem.vb.setLimits(xMin=0, xMax=max(self.x_1) + 1) self.graphics_view_2.plotItem.vb.setLimits(xMin=0, xMax=max(self.x_2) + 1) self.graphics_view_1.setMenuEnabled(False) self.graphics_view_2.setMenuEnabled(False) self.connection_chart = None self.graphics_view_3 = None
def __init__(self, x: list, y_1: list, y_2: list, graphics_view: PlotWidget, labels: str, units=None, x_labels=None, precision=0, width=0.4): """ Constructor / Instantiate the class Parameters ---------- x : list x-values y_1 : np.ndarray y-values y_2 : np.ndarray y-values graphics_view : PlotWidget widget to add items labels : str legend labels units : tuple measurement units for tuple x_labels : array-like array of x_labels precision : int precision for rounding, default is zero width : int, float width of any bars """ Assertor.assert_data_types([ x, y_1, y_2, graphics_view, labels, units, x_labels, precision, width ], [ list, list, list, PlotWidget, str, (type(None), tuple), (type(None), list), (float, int), (float, int) ]) super().__init__() self.y_1, self.x = self.create_bins(x, y_1, bins=x) self.y_2, self.x = self.create_bins(x, y_2, bins=x) self.x = self.x[:-1] self.labels = labels self.units = units if units else ("", "") self.precision = precision self.ratio = (self.y_1 / self.y_2) * 100 self.x_labels = x_labels if x_labels else self.ratio self.graphics_view = graphics_view self.view_box = self.graphics_view.getViewBox() self.width = width self.label = TextItem() self.bar_item_1 = BarGraphItem(x=self.x, height=self.ratio, width=self.width, brush="#a8ccec") self.graphics_view.addItem(self.bar_item_1) self.configure_cross_hair() self.bar_item_2 = None pen = mkPen(color="#4c96d7", style=Qt.SolidLine, width=1) self.vertical_line = InfiniteLine(angle=90, movable=False, pen=pen) self.graphics_view.addItem(self.vertical_line) self.graphics_view.plotItem.vb.setLimits(xMin=min(self.x) - width, xMax=max(self.x) + width) self.graphics_view.setMenuEnabled(False)
def __init__(self, x_1: list, y_1: list, x_2: list, y_2: list, graphics_view_1: PlotWidget, graphics_view_2: PlotWidget, labels: tuple, units=None, precision=0, width=1, average=None, display=int, x_labels=None, highlight_bars=True): """ Constructor / Instantiation of class Parameters ---------- x_1 : list x-values y_1 : list y-values x_2 : list x-values y_2 : list y-values graphics_view_1 : PlotWidget graphics view to place chart graphics_view_2 : PlotWidget graphics view to place chart labels : tuple labels for legend units : tuple, optional measurement units got labels precision : int precision for rounding, default is zero width : int, float width of any bars, default is 1 average : str average display : type display dtype for labels x_labels : array-like array of dates, i.e. time-period or other labels highlight_bars : bool whether to highlight bars in plot """ Assertor.assert_data_types( [x_1, y_1, x_2, y_2, graphics_view_1, graphics_view_2, labels, precision, average], [list, list, list, list, PlotWidget, PlotWidget, tuple, (int, float), (type(None), str)]) super().__init__() self.y_1, self.x_1 = self.create_bins(x_1, y_1, bins=x_1) self.y_2, self.x_2 = self.create_bins(x_2, y_2, bins=x_2) self.x_1 = self.x_1[:-1] self.x_2 = self.x_2[:-1] self.graphics_view_1 = graphics_view_1 self.graphics_view_2 = graphics_view_2 self.connection_chart = None self.graphics_view_3 = None if average: self.average = float(average) self.bar_item_1 = BarGraphItem(x=self.x_1, height=self.y_1, width=width, brush="#d2e5f5") self.bar_item_2 = BarGraphItem(x=self.x_2, height=self.y_2, width=width, brush="#d2e5f5") self.graphics_view_1.addItem(self.bar_item_1) self.graphics_view_2.addItem(self.bar_item_2) self.units = units if units else ("", "", "", "") if average: self.draw_average_line() self.cross_hair = DoubleCrossHair(self.x_1, self.y_1, self.x_2, self.y_2, self.graphics_view_1, self.graphics_view_2, labels, self.units, precision, width, display=display, x_labels=x_labels, highlight_bars=highlight_bars) self.add_cross_hair_to_chart() self.graphics_view_1.plotItem.vb.setLimits(xMin=min(self.x_1) - width, xMax=max(self.x_1) + width) self.graphics_view_2.plotItem.vb.setLimits(xMin=min(self.x_2) - width, xMax=max(self.x_2) + width) self.graphics_view_1.setMenuEnabled(False) self.graphics_view_2.setMenuEnabled(False)