Fix zooming in image plots with vertical orientation
Vertical image plots don't interact with the zoom tool correctly. Run the example below and use the scroll wheel to zoom out. As you zoom back in, the image jumps back and forth.
from scipy.misc import lena
from enable.api import Component, ComponentEditor
from traits.api import HasTraits, Instance
from traitsui.api import UItem, View
from chaco.api import ArrayPlotData, Plot
from chaco.tools.api import PanTool, ZoomTool
class Demo(HasTraits):
plot = Instance(Component)
traits_view = View(
UItem('plot', editor=ComponentEditor(size=(600, 600))),
resizable=True
)
def _plot_default(self):
pd = ArrayPlotData(imagedata=lena())
plot = Plot(pd, orientation='v')
plot.img_plot("imagedata")
plot.tools.append(PanTool(plot, constrain_key="shift"))
plot.overlays.append(ZoomTool(component=plot, always_on=False))
return plot
if __name__ == "__main__":
demo = Demo()
demo.configure_traits()
This certainly fixes the zooming issue, but it needs to be tested against lots of existing code before merging.
When running my current consulting project with this change, panning of image plots is a little wonky. That's likely due to some stupidity on my end (you're familiar with the code...), but it wasn't something I was expecting.
I just reverted changes to image_plot and left the changes to the zoom tool. The changes to image_plot were related to other issues anyway.
Just for reference, the "other issue" occurs when you replace the Plot call in the example with
plot = Plot(pd, default_origin='top left', orientation='v')
The change in origin causes zooming to slow down drastically at high zoom levels.