Hi Luke,
This is how the heatmap is implemented now, based on your suggestions:
A plot widget is created:
self.plot = pg.PlotWidget()
The heatmap class:
class Heatmap(pg.ImageItem):
def __init__(self, image=None):
if image is not None:
self.image = image
else:
self.image = np.zeros((500, 500))
pg.ImageItem.__init__(self, self.image)
def updateImage_(self, image, image_rect):
self.image[image_rect.y() : image_rect.y()+image.shape[0], image_rect.x() : image_rect.x()+image.shape[1]] = image
self.render()
self.update()
The first time the image is drawn like this:
self.hmi = Heatmap(colors)
self.plot.addItem(self.hmi)
self.hmi.setRect(QtCore.QRectF(self.X_min, self.Y_min, self.X_max-self.X_min, self.Y_max-self.Y_min))
And each time it gets updated:
self.hmi.updateImage_(colors, rect)
Now it works as I wanted:
- axes ranges are correct
- there is no historgram widget
- zoom and pan works as it should
And now, the questions:
1.) I have a question about this line of code you included:
pg.mkQApp()
What does it do?
2.) Also, I get a warning (was the same with previous implementation):
QApplication was created before pyqtgraph was imported; there may be problems (to avoid bugs, call QApplication.setGraphicsSystem("raster") before the QApplication is created).
It seems that everything is working correctly, but still: can I call setGraphicsSystem("raster") somewhere in my module - the whole application is pretty big, and I don't really know where the QApplication is created.
3.) Regarding point 6 from my first post (the user can select a region that should get updated):
I changed the design - I think this would be the most simple solution: (this is why I did not use mouseHoverEvent() and mouseDragEvent() in your solution)
Now, the User has two options:
1. she can zoom the image with mouse wheel and move it with left button drag, so that the region she wants to be updated, is displayed
2. she can zoom the image with right button drag: a box is drawn over a region of the scene and the scene is scaled and panned to fit the box
When the scene is zoomed, I would call
self.plot.viewRect()
to obtain the rect that is to be updated, calculate the updates, and then use
self.hmi.updateImage_(colors, rect)
to update the heatmap.
Would this be the correct approach?
While doing this, I am trying to set an option, so the mac user can also do the equivalent of right button drag:
pg.setConfigOption('leftButtonPan', False)
And this line has no effect - it is called, no errors, but the mouse behaviour doesn't change. It works if i right click on the scene and select 1button mouse mode. What am I missing?
Thank you for a fast reply yesterday, I was working on this for a couple of days now, and after reading your suggestions, I had it done in minutes... Thanks, your help is really appreciated :)
Jure
Dne četrtek, 23. januar 2014 02:59:18 UTC+1 je oseba Luke Campagnola napisala: