chaco icon indicating copy to clipboard operation
chaco copied to clipboard

Fix zooming in image plots with vertical orientation

Open tonysyu opened this issue 12 years ago • 3 comments

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()

tonysyu avatar Oct 30 '13 17:10 tonysyu

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.

jwiggins avatar Oct 30 '13 17:10 jwiggins

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.

tonysyu avatar Oct 30 '13 18:10 tonysyu

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.

tonysyu avatar Oct 30 '13 18:10 tonysyu