def on_job_shape_update(self): data = np.empty((2,0), dtype=np.float) connect = np.empty(0, dtype=np.bool) for path in self.job.get_shape_paths(): connected = np.ones(path.shape[1], dtype=np.bool) connected[-1] = False connect = np.concatenate((connect, connected)) data = np.concatenate((data, path), axis=1) self.fill_path = arrayToQPath(data[0], data[1], connect) paths, states = self.job.get_cut_paths() self.pen_base.setWidthF(self.job.kerf_width) # set pen for boundingRect to take it into account self.setPen(self.pen_base) data = [np.empty((2,0), dtype=np.float) for i in range(5)] connect = [np.empty(0, dtype=np.bool) for i in range(5)] for i, state in enumerate(states): connected = np.ones(paths[i].shape[1], dtype=np.bool) connected[-1] = False connect[state] = np.concatenate((connect[state], connected)) data[state] = np.concatenate((data[state], paths[i]), axis=1) self.cut_paths = [arrayToQPath(data[i][0], data[i][1], connect[i]) for i in range(len(self.cut_colors))] # last path is used to keep shape and boundingRect up to date self.setPath(self.cut_paths[states[-1]]) # TODO should take ALL paths # TODO breaking encapsulation to refresh handle on kerf with update self.controller.handle.update()
def __init__(self, x, y, pen): """x and y are 1D arrays representing the line's coordinates""" x = numpy.asarray(x) y = numpy.asarray(y) self.path = pyqtgraph.arrayToQPath(x.flatten(), y.flatten()) pyqtgraph.QtGui.QGraphicsPathItem.__init__(self, self.path) self.setPen(pyqtgraph.mkPen(pen))
def updateBoxes(self, ranges, penInt): # Remove the previous boxes for item in self.boxes: self.removeItem(item) self.boxes = [] # Skip, if no ranges to add if len(ranges) == 0: return # Try to merge these ranges (less lines)... # ...sort first by range start values ranges = np.array(ranges) ranges = ranges[np.argsort(ranges[:, 0])] merge = [ranges[0]] for rng in ranges: # In the case they do not overlap if rng[0] > merge[-1][1]: merge.append(rng) # If overlaping, and the new range extends further, push it elif rng[1] > merge[-1][1]: merge[-1][1] = rng[1] merge = np.array(merge) # Plot these efficiently (one disconnected line, rather than many lines) connect = np.ones((len(merge), 2), dtype=np.ubyte) connect[:, -1] = 0 # disconnect segment between lines path = pg.arrayToQPath(merge.reshape(len(merge) * 2), np.ones((len(merge) * 2)) * 0.5, connect.reshape(len(merge) * 2)) item = pg.QtGui.QGraphicsPathItem(path) item.setPen(pg.mkPen(QtGui.QColor(penInt))) # Add in the new box self.boxes.append(item) self.addItem(item)
def __init__(self, x, y): """x and y are 2D arrays of shape (Nplots, Nsamples)""" connect = np.ones(x.shape, dtype=bool) connect[:,-1] = 0 # don't draw the segment between each trace self.path = pg.arrayToQPath(x.flatten(), y.flatten(), connect.flatten()) pg.QtGui.QGraphicsPathItem.__init__(self, self.path) self.setPen(pg.mkPen('b',width=1))
def plot_trace_list(self, trace_list): app = pg.mkQApp() app.processEvents() ## Putting this at the beginning or end does not have much effect win = pg.GraphicsWindow(title="Basic plottting examples") win.resize(1000, 600) # Enable antialiasing for prettier plots pg.setConfigOptions(antialias=True) p = win.addPlot(title="x0-x1") xy = [] for trace in trace_list: x_array = trace.x_array #p.plot(x_array[:, 0:2]) xy.append(x_array) xy_array = np.vstack(xy) path = pg.arrayToQPath(xy_array[:, 0], xy_array[:, 1], connect='all') item = QtGui.QGraphicsPathItem(path) item.setPen(pg.mkPen('w')) p.addItem(item) #p.show() QtGui.QApplication.instance().exec_()
def __init__(self, x, y): conn = np.ones(x.shape, dtype=bool) conn[:, -1] = 0 self.path = pg.arrayToQPath(x.flatten(), y.flatten(), conn.flatten()) pg.QtGui.QGraphicsPathItem.__init__(self, self.path) self.setPen(pg.mkPen('w')) # White pen
def generatePicture(self): ## pre-computing a QPicture object allows paint() to run much more quickly, ## rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) # w = (self.data[1][0] - self.data[0][0]) / 3. x = self.xdat[:5] y = self.ydat[:5] self.path = pg.arrayToQPath(self.xdat, self.ydat, self.connect) # self.path = pg.arrayToQPath(np.array([0, 1, 1, 0, 3, 1]), np.array([0, 0, 1, 1, 3, 1])) p2 = QtGui.QPainterPath(self.path) p.fillPath(p2, pg.mkBrush((100, 100, 100))) # for (t, open, close, min, max) in self.data: # p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) # self.path = pg.arrayToQPath(np.array([0, 1, 2, 1]), np.array([0, 0, 1, 1])) # # self.path = self.generatePath([0, 1, 2, 1], [0, 0, 1, 1]) # p2 = QtGui.QPainterPath(self.path) # p.fillPath(p2, pg.mkBrush((100, 100, 100))) # if open > close: # p.setBrush(pg.mkBrush('r')) # else: # p.setBrush(pg.mkBrush('g')) # p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open)) # p.drawPolygon(QtCore.) # p.drawLine(QtCore.QPointF(*pts[i][0]), QtCore.QPointF(*pts[i][1])) p.end()
def ComputerSymbol(): """Symbol for computer device. Taken from: https://en.wikipedia.org/wiki/File:Simple_Monitor_Icon.svg and https://apps.automeris.io/wpd/ """ valves = np.asarray([[0.063, 0.91], [0.066, 0.93], [0.075, 0.96], [0.10, 0.98], [0.12, 0.99], [0.90, 0.99], [0.93, 0.98], [0.95, 0.96], [0.96, 0.94], [0.96, 0.92], [0.94, 0.24], [0.93, 0.21], [0.91, 0.19], [0.88, 0.17], [0.63, 0.17], [0.62, 0.068], [0.81, 0.063], [0.83, 0.054], [0.83, 0.041], [0.83, 0.024], [0.82, 0.0051], [0.81, -0.0013], [0.15, 0.0015], [0.14, 0.010], [0.13, 0.021], [0.13, 0.040], [0.14, 0.059], [0.16, 0.068], [0.34, 0.067], [0.35, 0.17], [0.35, 0.22], [0.87, 0.22], [0.88, 0.23], [0.89, 0.24], [0.91, 0.92], [0.91, 0.93], [0.89, 0.93], [0.13, 0.94], [0.12, 0.93], [0.11, 0.91], [0.089, 0.25], [0.095, 0.24], [0.11, 0.23], [0.35, 0.22], [0.35, 0.18], [0.090, 0.18], [0.070, 0.19], [0.054, 0.21], [0.038, 0.24]]) ones = np.ones((49, 2), dtype=float) new_valves = (valves - 0.5 * ones) return pg.arrayToQPath(new_valves[:, 0], new_valves[:, 1], connect='all')
def addObjs(self, lineWidth, symbol): pen = pg.mkPen((0, 0, 0), width=lineWidth) brushes = [pg.mkBrush(color) for color in layerColor] for z, (xs, ys) in enumerate(self.pointList): if len(xs) > 0: scatter = pg.ScatterPlotItem(size=15, pen=None, symbol=symbol, symbolBrush=brushes[z - 1]) scatter.addPoints(xs, ys) self.addObj(scatter, z) for z, lines in enumerate(self.lineList): if len(lines[0]) > 0: connect = np.ones(len(lines[0]), dtype=np.ubyte) connect[1::2] = 0 line = pg.arrayToQPath(np.array(lines[0]), np.array(lines[1]), connect) line = QtGui.QGraphicsPathItem(line) line.setPen(pen) self.addObj(line, z) self.totalObjInfo.append( (self.line2rect(lines), z, self.tmpBusName)) for z, rects in enumerate(self.rectList): if len(rects) > 0: obj = QtGui.QGraphicsItemGroup() for i, rect in enumerate(rects): rect = QtGui.QGraphicsRectItem(*rect) rect.setPen(pen) rect.setBrush(brushes[z - 1]) obj.addToGroup(rect) obj.mouseDoubleClickEvent = self.printInfo self.addObj(obj, z) self.totalObjInfo.append((rects, z, self.tmpBusName))
def __init__(self, x, y): """x and y are 2D arrays of shape (Nplots, Nsamples)""" connect = np.ones(x.shape, dtype=bool) connect[:, -1] = 0 # don't draw the segment between each trace self.path = pg.arrayToQPath(x.flatten(), y.flatten(), connect.flatten()) pg.QtGui.QGraphicsPathItem.__init__(self, self.path) self.setPen(pg.mkPen('w'))
def draw_tri(tri): tpts = pts[np.array(tri)] path = pg.arrayToQPath(tpts['x'], tpts['y']) shape = pg.QtGui.QGraphicsPathItem(path) shape.setPen(pg.mkPen(255,255,255,100)) shape.setBrush(pg.mkBrush(0,255,255,50)) win.addItem(shape) tri_shapes.append(shape)
def draw_tri(tri): tpts = pts[np.array(tri)] path = pg.arrayToQPath(tpts['x'], tpts['y']) shape = pg.QtGui.QGraphicsPathItem(path) shape.setPen(pg.mkPen(255, 255, 255, 100)) shape.setBrush(pg.mkBrush(0, 255, 255, 50)) win.addItem(shape) tri_shapes.append(shape)
def addPathPoint(self, pt): if self.pts is None: self.pts = [[pt.x()], [pt.y()]] else: self.pts[0].append(pt.x()) self.pts[1].append(pt.y()) self.path = pg.arrayToQPath(np.array(self.pts[0]), np.array(self.pts[1])) self.prepareGeometryChange()
def draw_segments(self, points, connect, color): path = pg.arrayToQPath(x=points[:,0], y=points[:,1], connect=connect) painter = self.painter with SaveRestore(painter): pen_color = QtGui.QColor(*[255.0 * c for c in color]) pen = QtGui.QPen(pen_color, self.outline_width)#, QtCore.Qt.SolidLine) painter.setPen(pen) #painter.setBrush(pen_color) painter.drawPath(path)
def __init__(self, x, y, size=1, alpha=80, color=(0, 0, 0)): """x and y are 2D arrays of shape (Nplots, Nsamples)""" connections = np.ones(x.shape, dtype=bool) connections[:, -1] = 0 # don't draw the segment between each trace self.path = pg.arrayToQPath(x.flatten(), y.flatten(), connections.flatten()) pg.QtWidgets.QGraphicsPathItem.__init__(self, self.path) pen = pg.mkPen(color + (alpha, ), width=size, cosmetic=True) self.setPen(pen)
def draw_connected(self): right_points = self._connected_airfoils.it_point_list_right left_points = self._connected_airfoils.it_point_list_left nb_points = len(left_points[0]) x = np.dstack((right_points[0], left_points[0])) y = np.dstack((right_points[1], left_points[1])) connected = np.dstack((np.ones(nb_points), np.zeros(nb_points))) path = pg.arrayToQPath(x.flatten(), y.flatten(), connected.flatten()) self.connection_lines_item.setPath(path)
def update_graph(self, graph, glist, cbox, number): """Updates the graph that displays the motors temperature""" if self.current_tab == number: graph.clear() graph.setXRange(-1, 21) for i in range(len(glist)): if cbox.currentText() == 'All' or cbox.currentIndex() - 1 == i: path = pg.arrayToQPath(np.arange(len(glist[i])), glist[i]) item = QtGui.QGraphicsPathItem(path) item.setPen(pg.mkPen(color=self.colorlist[i])) graph.addItem(item)
def __init__(self, x, y): """x and y are 2D arrays of shape (Nplots, Nsamples)""" self.xStart = None self.xCurrent = None self.linearRegionItem = None self.path = pg.arrayToQPath(x.flatten(), y.flatten(), connect='all') pg.QtGui.QGraphicsPathItem.__init__(self, self.path) # holy shit, this is bad, without this the app becomes non responsive??? # if width > 1.0 then this whole app STALLS self.setPen(pg.mkPen(color='k', width=1))
def generatePicture(self): ## pre-computing a QPicture object allows paint() to run much more quickly, ## rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) for i in range(int(len(self.xdat) / 5)): print(self.xdat[i*5:(i+1) * 5], self.ydat[i*5:(i+1) * 5]) self.path = pg.arrayToQPath(self.xdat[i * 5:(i+1) * 5], self.ydat[i * 5:(i+1) * 5]) # self.path = pg.arrayToQPath(np.array([0, 1, 1, 0, 3, 1]), np.array([0, 0, 1, 1, 3, 1])) p2 = QtGui.QPainterPath(self.path) p.fillPath(p2, pg.mkBrush((100, 100, 10 + i * 10))) p.end()
def generatePicture(self): """ Pre-compute a QPicture object to allow paint() to run much more quickly, :return: """ self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) for i in range(len(self.xdata)): path = pg.arrayToQPath(self.xdata[i], self.ydata[i]) p2 = QtGui.QPainterPath(path) p.fillPath(p2, pg.mkBrush((100, 100, 10 + i * 1))) p.end()
def _make_custom_verts(verts): """ Makes a custom symbol from the verts keyword accepted by scatter :param verts: sequence of (x, y) :return: str The name of the new custom key. It has been "installed" into pyqtgraph's Symbols dictionary. """ from pyqtgraph.graphicsItems.ScatterPlotItem import Symbols verts_x = np.array([vert[0] for vert in verts]) verts_y = np.array([vert[1] for vert in verts]) key = 'custom_pgmpl_symbol_1' Symbols[key] = pg.arrayToQPath(verts_x, verts_y, connect='all') return key
def draw_solid_polygons(self, points, connect, color): if points.size > 0: path = QtGui.QPainterPath() path.moveTo(pg.Point(points[0,:])) path2 = pg.arrayToQPath(x=points[:,0], y=points[:,1], connect=connect) path.addPath(path2) painter = self.painter with SaveRestore(painter): path.setFillRule(QtCore.Qt.WindingFill) brush_color = QtGui.QColor(*[255.0 * c for c in color]) pen_color = QtGui.QColor(*[100.0 * c for c in color]) pen = QtGui.QPen(pen_color, self.outline_width)#, QtCore.Qt.SolidLine) brush = QtGui.QBrush(brush_color) painter.setPen(pen) painter.setBrush(brush) path.moveTo(0,0) painter.drawPath(path)
def __init__(self, mask, contour, **kwargs): non_pg_kws = ['Main', 'label'] non_pg_vals = [kwargs.pop(key) for key in non_pg_kws] # pg.ROI needs a pos as the constructor. center of largest segment pos = sp.average(contour[sp.argmax([cont.shape[0] for cont in contour])], axis=0) self.contour = contour self.mask = mask pg.ROI.__init__(self, pos, size=(0, 0), **kwargs) myROI.__init__(self, **dict(list(zip(non_pg_kws, non_pg_vals)))) self.sigClicked.connect(self.clicked) # self.sigHoverEvent.connect(self.hover) # line self.lines = [] for segment in self.contour: x = segment[:, 0] y = segment[:, 1] # from itertools import chain # coords = list(chain.from_iterable(zip(x, y))) coords = list(zip(x, y)) ### polygon # # polygon # QPointList = [QtCore.QPoint(*coord) for coord in coords] # polygon = QtGui.QPolygonF(QPointList) # PolyItem = myQGraphicsPolygonItem(polygon,parent=self) # PolyItem.setPen(self.inactive_pen) # self.Main.MainWindow.Data_Display.Frame_Visualizer.ViewBox.addItem(PolyItem) ## line # line = myPlotDataItem(parent=self,pxMode=True,pen=self.inactive_pen) # line.setData(x=x,y=y) path = pg.arrayToQPath(x, y, connect='all') polygon = path.toFillPolygon() PolyItem = myQGraphicsPolygonItem(polygon, parent=self) PolyItem.setPen(self.inactive_pen) self.Main.MainWindow.Data_Display.Frame_Visualizer.ViewBox.addItem( PolyItem) self.lines.append(PolyItem) self.children.append(PolyItem)
def generatePicture(self): """ Pre-compute a QPicture object to allow paint() to run much more quickly, :return: """ self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen(self.pen_col)) for i in range(len(self.xdata)): path = pg.arrayToQPath(self.xdata[i], self.ydata[i]) p2 = QtGui.QPainterPath(path) if self.brushes is None: brush = pg.mkBrush((100, 100, 10 + i * 1)) else: brush = self.brushes[i] p.fillPath(p2, brush) p.drawPath(p2) p.end()
def __init__(self,mask,contour,**kwargs): non_pg_kws = ['Main','label'] non_pg_vals = [kwargs.pop(key) for key in non_pg_kws] # pg.ROI needs a pos as the constructor. center of largest segment pos = sp.average(contour[sp.argmax([cont.shape[0] for cont in contour])],axis=0) self.contour = contour self.mask = mask pg.ROI.__init__(self,pos,size=(0,0),**kwargs) myROI.__init__(self,**dict(zip(non_pg_kws,non_pg_vals))) self.sigClicked.connect(self.clicked) # self.sigHoverEvent.connect(self.hover) # line self.lines = [] for segment in self.contour: x = segment[:,0] y = segment[:,1] # from itertools import chain # coords = list(chain.from_iterable(zip(x, y))) coords = zip(x,y) ### polygon # # polygon # QPointList = [QtCore.QPoint(*coord) for coord in coords] # polygon = QtGui.QPolygonF(QPointList) # PolyItem = myQGraphicsPolygonItem(polygon,parent=self) # PolyItem.setPen(self.inactive_pen) # self.Main.MainWindow.Data_Display.Frame_Visualizer.ViewBox.addItem(PolyItem) ## line # line = myPlotDataItem(parent=self,pxMode=True,pen=self.inactive_pen) # line.setData(x=x,y=y) path = pg.arrayToQPath(x,y,connect='all') polygon = path.toFillPolygon() PolyItem = myQGraphicsPolygonItem(polygon,parent=self) PolyItem.setPen(self.inactive_pen) self.Main.MainWindow.Data_Display.Frame_Visualizer.ViewBox.addItem(PolyItem) self.lines.append(PolyItem) self.children.append(PolyItem)
def updateEveLines(self, fileTimes, curFile): # Remove the not-current event lines if self.otherEveLine != None: self.removeItem(self.otherEveLine) self.otherEveLine = None # Generate the many pick lines as one disconnected line if len(fileTimes) != 0: fileTimes = np.reshape(fileTimes, (len(fileTimes), 1)) times = np.hstack((fileTimes, fileTimes)) connect = np.ones((len(times), 2), dtype=np.ubyte) connect[:, -1] = 0 # disconnect segment between lines connect = connect.reshape(len(times) * 2) path = pg.arrayToQPath(times.reshape(len(times) * 2), connect, connect) item = pg.QtGui.QGraphicsPathItem(path) # Reference and plot the line self.otherEveLine = item self.addItem(item) # Generate and plot the current pick file (if present) self.updateEveLineSelect(curFile)
def fastPlot(): ## Different approach: generate a single item with all data points. ## This runs about 20x faster. start = pg.ptime.time() n = 15 pts = 100 x = np.linspace(0, 0.8, pts) y = np.random.random(size=pts)*0.8 xdata = np.empty((n, n, pts)) xdata[:] = x.reshape(1,1,pts) + np.arange(n).reshape(n,1,1) ydata = np.empty((n, n, pts)) ydata[:] = y.reshape(1,1,pts) + np.arange(n).reshape(1,n,1) conn = np.ones((n*n,pts)) conn[:,-1] = False # make sure plots are disconnected path = pg.arrayToQPath(xdata.flatten(), ydata.flatten(), conn.flatten()) item = QtGui.QGraphicsPathItem(path) item.setPen(pg.mkPen('w')) plt.addItem(item) dt = pg.ptime.time() - start
def fast_plot(plot_widget, x, y, pen=None): """[summary] Args: plot_widget ([type]): [description] x ([type]): [description] y ([type]): [description] pen ([type], optional): [description]. Defaults to None. """ # as per: https://stackoverflow.com/questions/17103698/plotting-large-arrays-in-pyqtgraph # not worth it when plotting all channels but may speed up drawing events conn = np.ones_like(x, dtype=np.bool) conn[:, -1] = False # make sure plots are disconnected path = pg.arrayToQPath(x.flatten(), y.flatten(), conn.flatten()) item = QtGui.QGraphicsPathItem(path) if pen is None: pen = pg.mkPen(color=(196, 128, 128)) item.setPen(pen) plot_widget.addItem(item) return item
def fastPlot(): ## Different approach: generate a single item with all data points. ## This runs about 20x faster. start = pg.ptime.time() n = 15 pts = 100 x = np.linspace(0, 0.8, pts) y = np.random.random(size=pts)*0.8 xdata = np.empty((n, n, pts)) xdata[:] = x.reshape(1,1,pts) + np.arange(n).reshape(n,1,1) ydata = np.empty((n, n, pts)) ydata[:] = y.reshape(1,1,pts) + np.arange(n).reshape(1,n,1) conn = np.ones((n*n,pts)) conn[:,-1] = False # make sure plots are disconnected path = pg.arrayToQPath(xdata.flatten(), ydata.flatten(), conn.flatten()) item = QtGui.QGraphicsPathItem(path) item.setPen(pg.mkPen('w')) plt.addItem(item) dt = pg.ptime.time() - start print("Create plots took: %0.3fms" % (dt*1000))
def __init__(self, x, y, slice='all', ds=1, col='w'): """x and y are 2D arrays of shape (Nplots, Nsamples). Slice is a logical vector saying which values to plot. If given, must be a vector of length nSamp. By default, it is 'all', and all samples are plotted. 'ds' is the downsampling factor. At the moment, it just subsamples, but could be made to do something better, like take the mean/max in each bin.""" if slice == 'all': connect = np.ones(x.shape, dtype=bool) connect = connect[:, ::ds] # downsample connect[:, -1] = 0 # don't draw the segment between each trace else: connect = np.zeros(x.shape, dtype=bool) connect[:, slice] = 1 # draw segments only between specified points connect = connect[:, ::ds] # downsample connect[:, -1] = 0 # just to make sure x = x[:, ::ds] y = y[:, ::ds] self.path = pg.arrayToQPath(x.flatten(), y.flatten(), connect.flatten()) pg.QtGui.QGraphicsPathItem.__init__(self, self.path) self.setPen(pg.mkPen(col))
def __init__(self, x, y, conn='all'): xr = x.min(), x.max() yr = y.min(), y.max() self._bounds = QtCore.QRectF(xr[0], yr[0], xr[1] - xr[0], yr[1] - yr[0]) self.path = pg.arrayToQPath(x, y, conn) QtGui.QGraphicsPathItem.__init__(self, self.path)
def time_test(self, nelems, connect): if connect == 'array': connect = self.connect_array pg.arrayToQPath(self.xdata, self.ydata, connect=connect)
def SwitchSymbol(): """Symbol for switch device.""" valves = np.asarray([[-0.9782608695652174, -0.49173553719008334], [0.9869565217391303, -0.4834710743801658], [0.9913043478260866, 0.49173553719008245], [-1, 0.475206611570248], [-0.991304347826087, 0.012396694214875659], [-0.7217391304347827, 0.037190082644627864], [-0.7217391304347827, -0.11983471074380159], [-0.4652173913043478, -0.11157024793388448], [-0.4782608695652175, 0.02892561983471076], [-0.40869565217391324, 0.02892561983471076], [-0.40869565217391324, -0.11157024793388448], [-0.15652173913043488, -0.10330578512396693], [-0.16086956521739137, 0.037190082644627864], [-0.16086956521739137, 0.037190082644627864], [-0.0913043478260871, 0.045454545454545414], [-0.10000000000000009, -0.09504132231404938], [0.15652173913043477, -0.08677685950413272], [0.15652173913043477, 0.02892561983471076], [0.21739130434782594, 0.037190082644627864], [0.21304347826086945, -0.08677685950413272], [0.4739130434782608, -0.09504132231404938], [0.4739130434782608, 0.02066115702479321], [0.5478260869565217, 0.037190082644627864], [0.5434782608695652, -0.09504132231404938], [0.8043478260869565, -0.12809917355371914], [0.8304347826086955, 0.2603305785123964], [0.7304347826086954, 0.2520661157024793], [0.7304347826086954, 0.2933884297520657], [0.6347826086956521, 0.2933884297520657], [0.6347826086956521, 0.23553719008264418], [0.5478260869565217, 0.24380165289256173], [0.5478260869565217, 0.06198347107438007], [0.4739130434782608, 0.05371900826446252], [0.4826086956521738, 0.23553719008264418], [0.3999999999999997, 0.23553719008264418], [0.3999999999999997, 0.2851239669421486], [0.3043478260869563, 0.2768595041322315], [0.3086956521739128, 0.22727272727272707], [0.21739130434782594, 0.23553719008264418], [0.21739130434782594, 0.06198347107438007], [0.16086956521739126, 0.05371900826446252], [0.16086956521739126, 0.23553719008264418], [0.08260869565217388, 0.24380165289256173], [0.08260869565217388, 0.2851239669421486], [-0.013043478260869712, 0.2851239669421486], [-0.013043478260869712, 0.24380165289256173], [-0.0913043478260871, 0.24380165289256173], [-0.0913043478260871, 0.07851239669421473], [-0.15652173913043488, 0.07851239669421473], [-0.15652173913043488, 0.23553719008264418], [-0.23478260869565226, 0.23553719008264418], [-0.23478260869565226, 0.2768595041322315], [-0.33043478260869585, 0.2768595041322315], [-0.33043478260869585, 0.23553719008264418], [-0.40869565217391324, 0.22727272727272707], [-0.40434782608695663, 0.05371900826446252], [-0.4739130434782609, 0.05371900826446252], [-0.482608695652174, 0.21900826446280997], [-0.5521739130434783, 0.22727272727272707], [-0.5565217391304349, 0.2851239669421486], [-0.6478260869565218, 0.26859504132231393], [-0.6478260869565218, 0.22727272727272707], [-0.7217391304347827, 0.22727272727272707], [-0.7217391304347827, 0.07024793388429762]]) new_valves = 0.7 * valves return pg.arrayToQPath(new_valves[:, 0], new_valves[:, 1], connect='all')
def set_slice(self, index=None, flip=None): # The flip has not been tested for vector display and is probably broke # if not self.vol: # if self.item: # self.viewbox.removeItem(self.item) # print 'not vol' # return if index < 0: return if not index: index = self.current_index else: self.current_index = index - 1 c = self.vol.subsampling scale = self.vol.scale if self.item: self.viewbox.removeItem(self.item) # Get the slice and 2D vectors for this orientation slice_ = self.slice_change_function(index) # Get the 2d vector for this plane slice_2d_vec = slice_.take(self.vector_axes, axis=2) x_points = [] y_points = [] connect = [] for y in range(0, slice_.shape[0] - c, c): for x in range(0, slice_.shape[1] -c, c): try: subsmapled_box = slice_2d_vec[y: y+c, x: x+c, :] except IndexError: print("fell off") else: x1 = x + (c/2) y1 = y + (c/2) x_magnitude, y_magnitude = np.mean(subsmapled_box, axis=(0, 1)) magnitude = np.linalg.norm((x_magnitude, y_magnitude)) if magnitude < self.vec_mag_min: continue if self.orientation == Orientation.axial: x_magnitude, y_magnitude = self.rotate_vector((x_magnitude, y_magnitude), -90.0) x_points.append(x1) y_points.append(y1) connect.append(1) # Draw a line to end of arrow x2 = x1 + (x_magnitude * scale) y2 = y1 + (y_magnitude * scale) x_points.append(x2) y_points.append(y2) connect.append(1) arrow_Xs, arrow_ys = self.draw_arrow_head(x2, x1, y2, y1) x_points.append(arrow_Xs[0]) y_points.append(arrow_ys[0]) connect.append(0) x_points.append(arrow_Xs[1]) y_points.append(arrow_ys[1]) connect.append(1) # Back to arrow tip x_points.append(x2) y_points.append(y2) connect.append(0) path = pg.arrayToQPath(np.array(x_points), np.array(y_points), np.array(connect)) self.item = QtGui.QGraphicsPathItem(path) self.item.setPen(pg.mkPen({'color': self.arrow_color, 'width': 1})) self.viewbox.addItem(self.item)
def setData(self, x_values, y_values): self.path = pg.arrayToQPath(x_values, y_values, 'all') self.setPath(self.path)
def __init__(self, pen): self.path = pg.arrayToQPath(np.zeros(0), np.zeros(0), 'all') pg.QtGui.QGraphicsPathItem.__init__(self, self.path) self.setPen(pen) self.last_time = None
def __init__(self, x, y, detectionWidget, type, width=1, forcePenColor=None, allowXAxisDrag=True): """ x and y are 2D arrays of shape (Nplots, Nsamples) type: (dvdt, vm) """ self.exportWidgetList = [] self.x = x self.y = y self.detectionWidget = detectionWidget self.myType = type self.allowXAxisDrag = allowXAxisDrag self.xDrag = None # if true, user is dragging x-axis, otherwise y-axis self.xStart = None self.xCurrent = None self.linearRegionItem = None if len(x.shape) == 2: connect = np.ones(x.shape, dtype=bool) connect[:, -1] = 0 # don't draw the segment between each trace self.path = pg.arrayToQPath(x.flatten(), y.flatten(), connect.flatten()) else: self.path = pg.arrayToQPath(x.flatten(), y.flatten(), connect='all') pg.QtGui.QGraphicsPathItem.__init__(self, self.path) doDarkTheme = True if forcePenColor is not None: penColor = forcePenColor elif doDarkTheme: penColor = 'w' else: penColor = 'k' # if self.myType == 'meanclip': penColor = 'r' width = 3 #print('MultiLine penColor:', penColor) logger.info(f'{self.myType} penColor: {penColor}') pen = pg.mkPen(color=penColor, width=width) # testing gradient pen ''' cm = pg.colormap.get('CET-L17') # prepare a linear color map #cm.reverse() # reverse it to put light colors at the top pen = cm.getPen( span=(0.0,1.0), width=5 ) # gradient from blue (y=0) to white (y=1) ''' # this works self.setPen(pen)