From bf1e59ca2290b5ba877e7938d46d562dc0383cc7 Mon Sep 17 00:00:00 2001 From: "Ingo B." Date: Thu, 3 Feb 2011 11:03:13 +0100 Subject: [PATCH 1/3] - changes to get some examples working on my side (test_PlotWidget.py, test_MultiPlotWidget.py) (ubuntu 10.10, python 2.6.6, qt 4.7.0, pyqt 4.7.4, numpy 1.3.0) --- PlotItem.py | 2 +- examples/test_PlotWidget.py | 3 ++- graphicsItems.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/PlotItem.py b/PlotItem.py index 0cbc9459..eb786f29 100644 --- a/PlotItem.py +++ b/PlotItem.py @@ -998,7 +998,7 @@ class PlotItem(QtGui.QGraphicsWidget): if arr.ndim != 1: raise Exception("Array must be 1D to plot (shape is %s)" % arr.shape) if x is None: - x = arange(arr.shape[0]) + x = np.arange(arr.shape[0]) if x.ndim != 1: raise Exception("X array must be 1D to plot (shape is %s)" % x.shape) c = PlotCurveItem(arr, x=x) diff --git a/examples/test_PlotWidget.py b/examples/test_PlotWidget.py index 80e4a9c4..a5f4960e 100755 --- a/examples/test_PlotWidget.py +++ b/examples/test_PlotWidget.py @@ -5,6 +5,7 @@ import sys, os sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) from scipy import random +from numpy import array, arange from PyQt4 import QtGui, QtCore from pyqtgraph.PlotWidget import * from pyqtgraph.graphicsItems import * @@ -90,4 +91,4 @@ for i in range(0, 5): yd, xd = rand(10000) pw2.plot(yd*(j+1), xd, params={'iter': i, 'val': j}) -#app.exec_() +app.exec_() diff --git a/graphicsItems.py b/graphicsItems.py index 299b9cf8..de935afa 100644 --- a/graphicsItems.py +++ b/graphicsItems.py @@ -573,7 +573,7 @@ class PlotCurveItem(GraphicsObject): self.xData = x if x is None: - self.xData = arange(0, self.yData.shape[0]) + self.xData = np.arange(0, self.yData.shape[0]) if self.xData.shape != self.yData.shape: raise Exception("X and Y arrays must be the same shape--got %s and %s." % (str(x.shape), str(y.shape))) From 56f54cbf9bc91899bf899ad1b1eba5ab4e58455b Mon Sep 17 00:00:00 2001 From: "Ingo B." Date: Thu, 3 Feb 2011 11:49:56 +0100 Subject: [PATCH 2/3] - added&enabled wheelEvent for PlotItem (symmetric scaling) --- GraphicsView.py | 3 +-- graphicsItems.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/GraphicsView.py b/GraphicsView.py index 852988fd..debbd533 100644 --- a/GraphicsView.py +++ b/GraphicsView.py @@ -219,15 +219,14 @@ class GraphicsView(QtGui.QGraphicsView): def wheelEvent(self, ev): + QtGui.QGraphicsView.wheelEvent(self, ev) if not self.mouseEnabled: return - QtGui.QGraphicsView.wheelEvent(self, ev) sc = 1.001 ** ev.delta() #self.scale *= sc #self.updateMatrix() self.scale(sc, sc) - def setAspectLocked(self, s): self.aspectLocked = s diff --git a/graphicsItems.py b/graphicsItems.py index de935afa..f6774f25 100644 --- a/graphicsItems.py +++ b/graphicsItems.py @@ -1491,7 +1491,16 @@ class ViewBox(QtGui.QGraphicsWidget): #self.replot(autoRange=False) #self.updateMatrix() - + def wheelEvent(self, ev): + mask = np.array(self.mouseEnabled, dtype=np.float) + degree = ev.delta() / 8.0; + dif = np.array([degree, degree]) + s = ((mask * 0.02) + 1) ** dif + center = Point(self.childGroup.transform().inverted()[0].map(ev.pos())) + self.scaleBy(s, center) + self.emit(QtCore.SIGNAL('rangeChangedManually'), self.mouseEnabled) + ev.accept() + def mouseMoveEvent(self, ev): pos = np.array([ev.pos().x(), ev.pos().y()]) dif = pos - self.mousePos From 1efb60a963bca595d46784a1f9f5e6c9dea50803 Mon Sep 17 00:00:00 2001 From: "Ingo B." Date: Mon, 7 Feb 2011 21:26:21 +0100 Subject: [PATCH 3/3] - ScaleItem: avoid drawing of multiple ticks at the same position --- graphicsItems.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/graphicsItems.py b/graphicsItems.py index f6774f25..d0486e2a 100644 --- a/graphicsItems.py +++ b/graphicsItems.py @@ -1221,8 +1221,10 @@ class ScaleItem(QtGui.QGraphicsWidget): else: xs = bounds.width() / dif + tickPositions = set() # remembers positions of previously drawn ticks ## draw ticks and text - for i in [i1, i1+1, i1+2]: ## draw three different intervals + ## draw three different intervals, long ticks first + for i in reversed([i1, i1+1, i1+2]): if i > len(intervals): continue ## spacing for this interval @@ -1266,7 +1268,11 @@ class ScaleItem(QtGui.QGraphicsWidget): if p1[1-axis] < 0: continue p.setPen(QtGui.QPen(QtGui.QColor(100, 100, 100, a))) - p.drawLine(Point(p1), Point(p2)) + # draw tick only if there is none + tickPos = p1[1-axis] + if tickPos not in tickPositions: + p.drawLine(Point(p1), Point(p2)) + tickPositions.add(tickPos) if i == textLevel: if abs(v) < .001 or abs(v) >= 10000: vstr = "%g" % (v * self.scale)