Skip to content

Instantly share code, notes, and snippets.

@sergey-miryanov
Created April 26, 2011 06:26
Show Gist options
  • Save sergey-miryanov/941877 to your computer and use it in GitHub Desktop.
Save sergey-miryanov/941877 to your computer and use it in GitHub Desktop.
example of use chaco + pyqt4
from math import ceil, sqrt
from PyQt4 import QtGui
from PyQt4.QtGui import QWidget
import numpy as np
from enthought.enable.api import Window
from enthought.chaco.api import \
ArrayDataSource, PlotAxis, \
LinearMapper, DataRange1D, LinePlot, \
GridContainer, PlotLabel, PlotGrid, \
OverlayPlotContainer, DataLabel
from enthought.chaco.tools.api import LineInspector, DataLabelTool
#from enthought.chaco.scales_axis import PlotAxis as ScalesPlotAxis
from ufsim.office.ui.chaco import RangeZoomTool, DatetimeTickGenerator
class ChartsWidget (QWidget) :
def __init__ (self, data, wells, charts) :
super (ChartsWidget, self).__init__ ()
self._grid = None
self._charts = charts
self._data = data
self._wells = wells
self.update ()
def control (self) :
return self._grid
def update (self) :
self._grid = None
self._buildGrid (self._data, self._wells, self._charts (selected = True))
def window (self) :
return Window (self, -1, component = self._grid)
def gridSize (self) :
charts = self._charts (selected = True)
columns = int (ceil (sqrt (len (charts))))
columns = columns if columns > 0 else 1
rows = int (len (charts) / columns)
if len (charts) % columns > 0 :
rows += 1
return (rows, columns)
def _buildGrid (self, data, wells, charts) :
rows, columns = self.gridSize ()
self._grid = GridContainer (padding = 15, fill_padding = True,
use_backbuffer = True, shape = (rows, columns), spacing = (0, 0))
for id, name, _path in charts :
container = OverlayPlotContainer (use_backbuffer = True)
history = data.history[id][wells.well]
rst = data.rst[id][wells.well]
dates = data.dates
dsIndex = ArrayDataSource (dates, sort_order="ascending")
mapperIndex = LinearMapper (range = DataRange1D (dsIndex))
v = np.append (history, rst)
dsValue = ArrayDataSource (v)
mapperValue = LinearMapper (range = DataRange1D (dsValue))
for color, value in [("red", history), ("blue", rst)] :
container.add (dataPlot (name, wells.well, color,
dsValue = ArrayDataSource (value),
dsIndex = dsIndex,
mapperIndex = mapperIndex,
mapperValue = mapperValue,
ticks = DatetimeTickGenerator (container)))
self._grid.add (container)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment