Skip to content

Instantly share code, notes, and snippets.

@gazzar
Created October 17, 2012 05:13
Show Gist options
  • Save gazzar/3903810 to your computer and use it in GitHub Desktop.
Save gazzar/3903810 to your computer and use it in GitHub Desktop.
Chaco FunctionImageData test
#!/usr/bin/env python
"""
Demonstrates use of the FunctionImageData that depends on an external range
and returns different data depending on that range.
"""
# Major library imports
from numpy import pi, linspace, meshgrid, sin
# Enthought library imports
from enable.api import Component, ComponentEditor
from traits.api import HasTraits, Instance, Int, Bool
from traitsui.api import Item, Group, HGroup, View
# Chaco imports
from chaco.api import ScatterPlot, DataView, LinePlot, Plot, ArrayPlotData, jet
from chaco.tools.api import PanTool, ZoomTool
from chaco.function_image_data import FunctionImageData
class PlotExample(HasTraits):
plot = Instance(Component)
use_tools = Bool(True)
sidelength = Int(20)
traits_view = View(
Group(
Item('plot', editor=ComponentEditor(size=(50,50)), show_label=False),
orientation = "vertical"),
resizable=True, title="Explore Plot",
width=600, height=600
)
def xyfunc(self, xlow, xhigh, ylow, yhigh):
print xlow, xhigh, ylow, yhigh
xs = linspace(xlow, xhigh, 300)
ys = linspace(ylow, yhigh, 300)
x, y = meshgrid(xs,ys)
return sin(1/x)*sin(1/y)
def _plot_default(self):
pd = ArrayPlotData()
fid = FunctionImageData(func = self.xyfunc)
fid._data = self.xyfunc(-1,1,-1,1)
pd.set_data("imagedata", fid)
plot = Plot(pd)
img_plot = plot.img_plot("imagedata", colormap=jet,
interpolation='nearest',
xbounds=(-1.0, 1.0),
ybounds=(-1.0, 1.0))[0]
fid.data_range = plot.range2d
plot.tools.append(PanTool(plot))
plot.tools.append(ZoomTool(plot))
return plot
demo = PlotExample()
if __name__ == "__main__":
demo.configure_traits()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment