Uwe
2011-07-29 15:14:59 UTC
Hi,
in the minimal example below I get a wrong x value, the y value is
right.
If I position the mouse in the upper left corner of the plot area, the
event tells me y=0 what is right, but x>0. I have to move the mouse
to the left of the y-axis tick markers to get x = 0.
What am I doing wrong ??
Regards, Uwe
#####################################################
# -*- coding: utf-8 -*-
from PyQt4.QtGui import QVBoxLayout, QDialog
from guiqwt.plot import CurveWidget, PlotManager
from guiqwt.builder import make
from guiqwt.tools import SelectTool
import numpy as np
class TestDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
vlayout = QVBoxLayout()
self.setLayout(vlayout)
self.widget = CurveWidget()
self.curve_item = make.curve([], [], color='b')
self.widget.plot.add_item(self.curve_item)
self.pm = PlotManager(self.widget)
self.pm.add_plot(self.widget.plot)
t = self.pm.add_tool(SelectTool)
self.pm.set_default_tool(t)
t.activate()
def dce(evt):
print evt.pos()
plot = self.curve_item.plot()
print plot.invTransform(self.curve_item.xAxis(), evt.x())
print plot.invTransform(self.curve_item.yAxis(), evt.y())
print
self.widget.plot.mouseReleaseEvent = dce
self.layout().addWidget(self.widget)
self.update_curve()
def update_curve(self):
x = np.arange(0,10,.1)
y = np.sin(np.sin(x))
self.curve_item.set_data(x, y)
self.curve_item.plot().replot()
if __name__ == '__main__':
from PyQt4.QtGui import QApplication
app = QApplication([])
win = TestDialog()
win.show()
app.exec_()
in the minimal example below I get a wrong x value, the y value is
right.
If I position the mouse in the upper left corner of the plot area, the
event tells me y=0 what is right, but x>0. I have to move the mouse
to the left of the y-axis tick markers to get x = 0.
What am I doing wrong ??
Regards, Uwe
#####################################################
# -*- coding: utf-8 -*-
from PyQt4.QtGui import QVBoxLayout, QDialog
from guiqwt.plot import CurveWidget, PlotManager
from guiqwt.builder import make
from guiqwt.tools import SelectTool
import numpy as np
class TestDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
vlayout = QVBoxLayout()
self.setLayout(vlayout)
self.widget = CurveWidget()
self.curve_item = make.curve([], [], color='b')
self.widget.plot.add_item(self.curve_item)
self.pm = PlotManager(self.widget)
self.pm.add_plot(self.widget.plot)
t = self.pm.add_tool(SelectTool)
self.pm.set_default_tool(t)
t.activate()
def dce(evt):
print evt.pos()
plot = self.curve_item.plot()
print plot.invTransform(self.curve_item.xAxis(), evt.x())
print plot.invTransform(self.curve_item.yAxis(), evt.y())
self.widget.plot.mouseReleaseEvent = dce
self.layout().addWidget(self.widget)
self.update_curve()
def update_curve(self):
x = np.arange(0,10,.1)
y = np.sin(np.sin(x))
self.curve_item.set_data(x, y)
self.curve_item.plot().replot()
if __name__ == '__main__':
from PyQt4.QtGui import QApplication
app = QApplication([])
win = TestDialog()
win.show()
app.exec_()