2010-03-22 05:48:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
MultiPlotItem.py - Graphics item used for displaying an array of PlotItems
|
|
|
|
Copyright 2010 Luke Campagnola
|
|
|
|
Distributed under MIT/X11 license. See license.txt for more infomation.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from numpy import ndarray
|
2012-05-11 22:05:41 +00:00
|
|
|
from . import GraphicsLayout
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
from metaarray import *
|
|
|
|
HAVE_METAARRAY = True
|
|
|
|
except:
|
2010-03-22 06:21:56 +00:00
|
|
|
#raise
|
2010-03-22 05:48:52 +00:00
|
|
|
HAVE_METAARRAY = False
|
|
|
|
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
__all__ = ['MultiPlotItem']
|
|
|
|
class MultiPlotItem(GraphicsLayout.GraphicsLayout):
|
|
|
|
"""
|
|
|
|
Automaticaly generates a grid of plots from a multi-dimensional array
|
|
|
|
"""
|
|
|
|
|
2010-03-22 05:48:52 +00:00
|
|
|
def plot(self, data):
|
|
|
|
#self.layout.clear()
|
|
|
|
self.plots = []
|
|
|
|
|
2012-06-18 17:45:47 +00:00
|
|
|
if HAVE_METAARRAY and (hasattr(data, 'implements') and data.implements('MetaArray')):
|
2010-03-22 05:48:52 +00:00
|
|
|
if data.ndim != 2:
|
|
|
|
raise Exception("MultiPlot currently only accepts 2D MetaArray.")
|
|
|
|
ic = data.infoCopy()
|
|
|
|
ax = 0
|
|
|
|
for i in [0, 1]:
|
|
|
|
if 'cols' in ic[i]:
|
|
|
|
ax = i
|
|
|
|
break
|
|
|
|
#print "Plotting using axis %d as columns (%d plots)" % (ax, data.shape[ax])
|
|
|
|
for i in range(data.shape[ax]):
|
2012-03-02 02:55:32 +00:00
|
|
|
pi = self.addPlot()
|
|
|
|
self.nextRow()
|
2010-03-22 05:48:52 +00:00
|
|
|
sl = [slice(None)] * 2
|
|
|
|
sl[ax] = i
|
|
|
|
pi.plot(data[tuple(sl)])
|
2012-03-02 02:55:32 +00:00
|
|
|
#self.layout.addItem(pi, i, 0)
|
2010-03-22 05:48:52 +00:00
|
|
|
self.plots.append((pi, i, 0))
|
|
|
|
title = None
|
|
|
|
units = None
|
|
|
|
info = ic[ax]['cols'][i]
|
|
|
|
if 'title' in info:
|
|
|
|
title = info['title']
|
|
|
|
elif 'name' in info:
|
|
|
|
title = info['name']
|
|
|
|
if 'units' in info:
|
|
|
|
units = info['units']
|
|
|
|
|
|
|
|
pi.setLabel('left', text=title, units=units)
|
|
|
|
|
|
|
|
else:
|
|
|
|
raise Exception("Data type %s not (yet?) supported for MultiPlot." % type(data))
|
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
def close(self):
|
|
|
|
for p in self.plots:
|
|
|
|
p[0].close()
|
2011-04-25 12:51:18 +00:00
|
|
|
self.plots = None
|
2012-03-02 02:55:32 +00:00
|
|
|
self.clear()
|
|
|
|
|
|
|
|
|
|
|
|
|