[Yt-svn] yt: Adding support for multiple fields as well as a zoomed plot ...
hg at spacepope.org
hg at spacepope.org
Sun Mar 28 23:31:57 PDT 2010
hg Repository: yt
details: yt/rev/c248cd4313a8
changeset: 1494:c248cd4313a8
user: Matthew Turk <matthewturk at gmail.com>
date:
Sun Mar 28 23:31:52 2010 -0700
description:
Adding support for multiple fields as well as a zoomed plot updater for inset
plots.
diffstat:
yt/extensions/image_panner/pan_and_scan_widget.py | 43 ++++++++++++++++++---
yt/extensions/image_panner/vm_panner.py | 2 +
2 files changed, 39 insertions(+), 6 deletions(-)
diffs (114 lines):
diff -r 4fa0bfdfdb95 -r c248cd4313a8 yt/extensions/image_panner/pan_and_scan_widget.py
--- a/yt/extensions/image_panner/pan_and_scan_widget.py Sun Mar 28 19:29:48 2010 -0700
+++ b/yt/extensions/image_panner/pan_and_scan_widget.py Sun Mar 28 23:31:52 2010 -0700
@@ -34,7 +34,7 @@
# Chaco imports
from enthought.chaco.api import ArrayPlotData, jet, Plot, HPlotContainer, \
ColorBar, DataRange1D, DataRange2D, LinearMapper, ImageData, \
- CMapImagePlot
+ CMapImagePlot, OverlayPlotContainer
from enthought.chaco.tools.api import PanTool, ZoomTool, RangeSelection, \
RangeSelectionOverlay, RangeSelection
from zoom_overlay import ZoomOverlay
@@ -84,11 +84,14 @@
class ImagePixelizerHelper(object):
index = None
- def __init__(self, panner):
+ def __init__(self, panner, run_callbacks = False):
self.panner = panner
+ self.run_callbacks = run_callbacks
def __call__(self, low, high):
b = self.panner.set_low_high(low, high)
+ if self.run_callbacks:
+ self.panner._run_callbacks()
if self.index is not None:
num_x_ticks = b.shape[0] + 1
num_y_ticks = b.shape[1] + 1
@@ -97,6 +100,29 @@
self.index.set_data( xs, ys )
return b
+class ZoomedPlotUpdater(object):
+ fid = None
+ def __init__(self, panner, zoom_factor=4):
+ """
+ Supply this an a viewport_callback argument to a panner if you want to
+ update a second panner in a smaller portion at higher resolution. If
+ you then set the *fid* property, you can also have it update a
+ FunctionImageData datarange. *panner* is the panner to update (not the
+ one this is a callback to) and *zoom_factor* is how much to zoom in by.
+ """
+ self.panner = panner
+ self.zoom_factor = zoom_factor
+
+ def __call__(self, xlim, ylim):
+ self.panner.xlim = xlim
+ self.panner.ylim = ylim
+ self.panner.zoom(self.zoom_factor)
+ nxlim = self.panner.xlim
+ nylim = self.panner.ylim
+ if self.fid is not None:
+ self.fid.data_range.set_bounds(
+ (nxlim[0], nylim[0]), (nxlim[1], nylim[1]))
+
class VMImagePlot(HasTraits):
plot = Instance(Plot)
fid = Instance(FunctionImageData)
@@ -112,7 +138,7 @@
def _plot_default(self):
pd = ArrayPlotData()
- plot = Plot(pd)
+ plot = Plot(pd, padding = 0)
self.fid._data = self.panner.buffer
pd.set_data("imagedata", self.fid)
@@ -150,10 +176,13 @@
spawn_zoom = Button
vm_plot = Instance(VMImagePlot)
use_tools = Bool(True)
+ full_container = Instance(HPlotContainer)
+ container = Instance(OverlayPlotContainer)
traits_view = View(
Group(
- Item('container', editor=ComponentEditor(size=(512,512)),
+ Item('full_container',
+ editor=ComponentEditor(size=(512,512)),
show_label=False),
Item('field', show_label=False),
orientation = "vertical"),
@@ -209,8 +238,10 @@
# the selection, so set that up as well
range_selection.listeners.append(img_plot)
- self.container = HPlotContainer(padding=30)
- self.container.add(self.colorbar)
+ self.full_container = HPlotContainer(padding=30)
+ self.container = OverlayPlotContainer(padding=0)
+ self.full_container.add(self.colorbar)
+ self.full_container.add(self.container)
self.container.add(self.vm_plot.plot)
def _spawn_zoom_fired(self):
diff -r 4fa0bfdfdb95 -r c248cd4313a8 yt/extensions/image_panner/vm_panner.py
--- a/yt/extensions/image_panner/vm_panner.py Sun Mar 28 19:29:48 2010 -0700
+++ b/yt/extensions/image_panner/vm_panner.py Sun Mar 28 23:31:52 2010 -0700
@@ -29,6 +29,7 @@
class VariableMeshPanner(object):
_buffer = None
+ _hold = False
def __init__(self, source, size, field, callback = None,
viewport_callback = None):
@@ -56,6 +57,7 @@
self.xlim, self.ylim = self.bounds
def _run_callbacks(self):
+ if self._hold: return
self.callback(self.buffer)
self.viewport_callback(self.xlim, self.ylim)
More information about the yt-svn
mailing list