File: MultiPlotItem.py

package info (click to toggle)
python-pyqtgraph 0.9.8-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,552 kB
  • ctags: 4,262
  • sloc: python: 30,181; makefile: 116; sh: 1
file content (69 lines) | stat: -rw-r--r-- 2,101 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- 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
from . import GraphicsLayout

try:
    from metaarray import *
    HAVE_METAARRAY = True
except:
    #raise
    HAVE_METAARRAY = False
    

__all__ = ['MultiPlotItem']
class MultiPlotItem(GraphicsLayout.GraphicsLayout):
    """
    Automaticaly generates a grid of plots from a multi-dimensional array
    """
    
    def plot(self, data):
        #self.layout.clear()
        self.plots = []
            
        if HAVE_METAARRAY and (hasattr(data, 'implements') and data.implements('MetaArray')):
            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]):
                pi = self.addPlot()
                self.nextRow()
                sl = [slice(None)] * 2
                sl[ax] = i
                pi.plot(data[tuple(sl)])
                #self.layout.addItem(pi, i, 0)
                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))
            
    def close(self):
        for p in self.plots:
            p[0].close()
        self.plots = None
        self.clear()