|
1 | 1 | # note, this is currentl *very slow*. I'm working on improving the |
2 | 2 | # efficiency of pcolor. If you want to run this example and your |
3 | 3 | # computer is not very fast, I suggest you grab a cup of coffee while |
4 | | -# it runs |
| 4 | +# it runs. Look for major improvments in pcolor in future releases of |
| 5 | +# matplotlib when we add image handling capability in extension module |
| 6 | +# code |
5 | 7 |
|
| 8 | +from __future__ import division |
6 | 9 | from matplotlib.matlab import * |
7 | 10 | from matplotlib.lines import Line2D |
8 | | - |
| 11 | +from matplotlib.transforms import Transform, Bound1D |
9 | 12 | # I use if 1 to break up the different regions of code visually |
10 | 13 |
|
11 | 14 | if 1: # load the data |
|
40 | 43 | t = arange(numSamples)/float(numSamples)*10.0 |
41 | 44 | ticklocs = [] |
42 | 45 | ax = subplot(212) |
| 46 | + |
| 47 | + height = 72 # height of one EEG in pixels |
| 48 | + # transform data to axes coord (0,1) |
| 49 | + transy = Transform(Bound1D(-.05,.05), Bound1D(-.2,.2)) |
43 | 50 | for i in range(numRows): |
44 | | - thisLine = Line2D(ax.dpi, ax.bbox, t, data[:,i]-data[0,i], |
45 | | - transx=ax.xaxis.transData, transy=ax.yaxis.transData) |
46 | | - thisLine.set_vertical_offset(3*i) |
| 51 | + thisLine = Line2D( |
| 52 | + ax.dpi, ax.bbox, t, data[:,i]-data[0,i], |
| 53 | + transx=ax.xaxis.transData, |
| 54 | + transy=transy) |
| 55 | + offset = (i+1)/(numRows+1) |
| 56 | + thisLine.set_vertical_offset(offset, ax.yaxis.transAxis) |
| 57 | + |
47 | 58 | ax.add_line(thisLine) |
48 | | - ticklocs.append(3*i) |
| 59 | + ticklocs.append(offset) |
49 | 60 |
|
| 61 | + set(gca(), 'xlim', [0,10]) |
50 | 62 | set(gca(), 'xticks', arange(10)) |
51 | | - set(gca(), 'yticks', ticklocs) |
52 | | - set(gca(), 'yticklabels', ['PG3', 'PG5', 'PG7', 'PG9']) |
53 | | - #set(gca(), 'ylim', [0, 20]) |
| 63 | + yticks = set(gca(), 'yticks', ticklocs) |
| 64 | + set(gca(), 'yticklabels', ['PG3', 'PG5', 'PG7', 'PG9']) |
| 65 | + |
| 66 | + # set the yticks to use axes coords on the y axis |
| 67 | + set(yticks, 'transform', ax.yaxis.transAxis) |
54 | 68 | xlabel('time (s)') |
55 | 69 |
|
56 | 70 |
|
|
0 commit comments