diff --git a/GraphicsView.py b/GraphicsView.py index edfc2d86..dda96506 100644 --- a/GraphicsView.py +++ b/GraphicsView.py @@ -226,15 +226,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/PlotItem.py b/PlotItem.py index 286e621e..336e659d 100644 --- a/PlotItem.py +++ b/PlotItem.py @@ -953,7 +953,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 8c98ca22..76dab924 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(y=yd*(j+1), x=xd, params={'iter': i, 'val': j}) -#app.exec_() +app.exec_() diff --git a/graphicsItems.py b/graphicsItems.py index a5ac37f6..bd6bff35 100644 --- a/graphicsItems.py +++ b/graphicsItems.py @@ -1458,8 +1458,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 @@ -1503,7 +1505,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) @@ -1728,7 +1734,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): QtGui.QGraphicsWidget.mouseMoveEvent(self, ev) pos = np.array([ev.pos().x(), ev.pos().y()])