Skip to content

Instantly share code, notes, and snippets.

@Snegovikufa
Created July 17, 2012 04:15
Show Gist options
  • Save Snegovikufa/3127079 to your computer and use it in GitHub Desktop.
Save Snegovikufa/3127079 to your computer and use it in GitHub Desktop.
Chaco multiple plots and axes
def view (self, data) :
index, filteredIndex = self.dataIndex (data)
indexData = ArrayDataSource (filteredIndex, sort_order = "ascending")
indexMapper = LinearMapper (range = DataRange1D (indexData))
grid = ChacoGridContainer (padding = 35,
padding_bottom = 65,
fill_padding = True,
use_backbuffer = True,
shape = gridShape (len (self._grid)),
spacing = (0, 0))
containers = []
axisWidth = Config.get ("Charts", "axisWidth")
labelFontSize = Config.get ("Charts", "labelFontSize")
labelFontBold = Config.get ("Charts", "labelFontBold")
labelFont = "Sans %s %s" % (labelFontSize, "bold" if labelFontBold else "")
for plot in self._grid :
container = PlotContainer (
_dates = filteredIndex,
range_ = True,
template = self,
bgcolor = "yellow")
container.setTemplate (self)
axes = {}
mappers = {}
for i, line in enumerate (plot.lines ()) :
value = ArrayDataSource (line.data (data, index))
res_type = getResourceType (line)
if res_type not in mappers :
mappers[res_type] = LinearMapper (
range = DataRange1D (value))
p = line.plot (
(indexData, indexMapper),
(value, mappers[res_type]))
if res_type not in axes :
axes[res_type] = (PlotAxis (mapper = mappers[res_type],
orientation = "right",
resizable = 'v',
padding_left = 10,
padding_right = 10,
title = "%s" % res_type,
bounds = [axisWidth, 0],
tick_label_font = labelFont,
tick_label_formatter = labelFormatter,
border_visible = False))
container.add (line.name (), p)
containers.append (container)
axesCount = len(axes)
hcontainer = HPlotContainer (
bgcolor = "blue")
hcontainer.add (container.plot ("%s: %s" % (self._name, plot.name ()),
self._xaxis))
for axis in axes.values () :
hcontainer.add (axis)
grid.add (hcontainer)
return grid, indexData, indexMapper, containers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment