|
7 | 7 | from matplotlib.matlab import * |
8 | 8 | from matplotlib.lines import Line2D |
9 | 9 | from matplotlib.transforms import get_bbox_transform, Point, Value, Bbox,\ |
10 | | - translation_transform, zero |
| 10 | + unit_bbox |
| 11 | + |
| 12 | + |
11 | 13 | # I use if 1 to break up the different regions of code visually |
12 | 14 |
|
13 | 15 | if 1: # load the data |
|
41 | 43 | ticklocs = [] |
42 | 44 | ax = subplot(212) |
43 | 45 |
|
44 | | - height = 72 # height of one EEG in pixels |
45 | | - # transform data to axes coord (0,1) |
46 | | - |
| 46 | + boxin = Bbox( |
| 47 | + Point(ax.viewLim.ll().x(), Value(-20)), |
| 48 | + Point(ax.viewLim.ur().x(), Value(20))) |
| 49 | + |
| 50 | + |
| 51 | + height = ax.bbox.ur().y() - ax.bbox.ll().y() |
| 52 | + boxout = Bbox( |
| 53 | + Point(ax.bbox.ll().x(), Value(-1)*height), |
| 54 | + Point(ax.bbox.ur().x(), Value(1) * height)) |
| 55 | + |
| 56 | + |
| 57 | + transOffset = get_bbox_transform( |
| 58 | + unit_bbox(), |
| 59 | + Bbox( Point( Value(0), ax.bbox.ll().y()), |
| 60 | + Point( Value(1), ax.bbox.ur().y()) |
| 61 | + )) |
| 62 | + |
47 | 63 |
|
48 | 64 | for i in range(numRows): |
49 | | - trans = get_bbox_transform(ax.viewLim, ax.bbox) |
| 65 | + # effectively a copy of transData |
| 66 | + trans = get_bbox_transform(boxin, boxout) |
50 | 67 | offset = (i+1)/(numRows+1) |
51 | | - height = Value(offset) * (ax.bbox.ur().y() - ax.bbox.ll().y()) |
52 | | - trans.set_offset( (0,0), translation_transform(zero(), height) ) |
| 68 | + |
| 69 | + trans.set_offset( (0, offset), transOffset) |
53 | 70 |
|
54 | 71 | thisLine = Line2D( |
55 | 72 | t, data[:,i]-data[0,i], |
|
61 | 78 | ticklocs.append(offset) |
62 | 79 |
|
63 | 80 | set(gca(), 'xlim', [0,10]) |
64 | | - set(gca(), 'ylim', [0,200]) |
65 | 81 | set(gca(), 'xticks', arange(10)) |
66 | | - yticks = set(gca(), 'yticks', ticklocs) |
| 82 | + |
67 | 83 | set(gca(), 'yticklabels', ['PG3', 'PG5', 'PG7', 'PG9']) |
68 | 84 |
|
69 | 85 | # set the yticks to use axes coords on the y axis |
70 | | - set(yticks, 'transform', ax.transAxes) |
| 86 | + ax.set_yticks(ticklocs) |
| 87 | + for tick in ax.yaxis.get_major_ticks(): |
| 88 | + tick.label1.set_transform(ax.transAxes) |
| 89 | + tick.label2.set_transform(ax.transAxes) |
| 90 | + tick.tick1line.set_transform(ax.transAxes) |
| 91 | + tick.tick2line.set_transform(ax.transAxes) |
| 92 | + tick.gridline.set_transform(ax.transAxes) |
| 93 | + |
| 94 | + |
71 | 95 | xlabel('time (s)') |
72 | 96 |
|
73 | 97 |
|
|
0 commit comments