From: Sébastien / Seb-b. <seb...@gm...> - 2008-10-16 17:42:13
|
Hi folks, I have a few plots which I would like to stack in a single figure. When I first came with this problem (back to matplotlib version 0.93 or older), the most efficient way (at least in my case) of doing this consisted in playing with transformations as you can see in the cookbook (see: http://www.scipy.org/Cookbook/Matplotlib/MultilinePlots#head-b5f2ad87ab7ec637a0fc63ec85281469d9aeeb46). Unfortunately, this example (and, of course, the script I wrote back then) doesn't work anymore with with the newest version of Matplotlib (0.98). So I started to hack the "mri_with_eeg.py" example to achieve what I want (since the way EEGs are stacked!)... with no luck! I probably don't understand well how the transformation works... That's why I decided to beg for a friendly help! :) Here is the code from the example (I focused on the lines I haven't completely figured): boxin = Bbox.from_extents(ax.viewLim.x0, -20, ax.viewLim.x1, 20) height = ax.bbox.height boxout = Bbox.from_extents(ax.bbox.x0, -1.0 * height, ax.bbox.x1, 1.0 * height) transOffset = BboxTransformTo( Bbox.from_extents(0.0, ax.bbox.y0, 1.0, ax.bbox.y1)) for i in range(numRows): # effectively a copy of transData trans = BboxTransform(boxin, boxout) offset = (i+1)/(numRows+1) trans += Affine2D().translate(*transOffset.transform_point((0, offset))) thisLine = Line2D( t, data[:,i]-data[0,i], ) thisLine.set_transform(trans) ax.add_line(thisLine) ticklocs.append(offset) ax being a AxesSubplot instance as far as I understood, 20 and -20 (see line where boxin is defined) refer to min and max values (on Y axis) to be plotted within the space allocated to each plot (thanks to the tranformation named trans). In my case Y values can be much higher (roughly from -1e3 to 5e7), so I should change those values according to mine in order to get the tranformation working for me. Obviously something is wrong in my understanding since it doesn't work! Hence my first question: Why is it not working? As a bonus, I also have another question: Is there a "new" (i.e. provided by the new API) way that can be used to stack plots composed by many (>5k) points? Thanks Sébastien |
From: Eric F. <ef...@ha...> - 2008-10-16 19:35:12
Attachments:
mri_with_eeg.py
|
Sébastien / Seb-bubuntu wrote: > Hi folks, > > I have a few plots which I would like to stack in a single figure. When > I first came with this problem (back to matplotlib version 0.93 or > older), the most efficient way (at least in my case) of doing this > consisted in playing with transformations as you can see in the cookbook > (see: > http://www.scipy.org/Cookbook/Matplotlib/MultilinePlots#head-b5f2ad87ab7ec637a0fc63ec85281469d9aeeb46). > Unfortunately, this example (and, of course, the script I wrote back > then) doesn't work anymore with with the newest version of Matplotlib > (0.98). > So I started to hack the "mri_with_eeg.py" example to achieve what I > want (since the way EEGs are stacked!)... with no luck! > I probably don't understand well how the transformation works... That's > why I decided to beg for a friendly help! :) > > Here is the code from the example (I focused on the lines I haven't > completely figured): > > boxin = Bbox.from_extents(ax.viewLim.x0, -20, ax.viewLim.x1, 20) > > height = ax.bbox.height > boxout = Bbox.from_extents(ax.bbox.x0, -1.0 * height, > ax.bbox.x1, 1.0 * height) > > transOffset = BboxTransformTo( > Bbox.from_extents(0.0, ax.bbox.y0, 1.0, ax.bbox.y1)) > > > for i in range(numRows): > # effectively a copy of transData > trans = BboxTransform(boxin, boxout) > offset = (i+1)/(numRows+1) > > trans += Affine2D().translate(*transOffset.transform_point((0, > offset))) > > thisLine = Line2D( > t, data[:,i]-data[0,i], > ) > > thisLine.set_transform(trans) > > ax.add_line(thisLine) > ticklocs.append(offset) > > ax being a AxesSubplot instance > as far as I understood, 20 and -20 (see line where boxin is defined) > refer to min and max values (on Y axis) to be plotted within the space > allocated to each plot (thanks to the tranformation named trans). > In my case Y values can be much higher (roughly from -1e3 to 5e7), so I > should change those values according to mine in order to get the > tranformation working for me. Obviously something is wrong in my > understanding since it doesn't work! > Hence my first question: Why is it not working? > As a bonus, I also have another question: Is there a "new" (i.e. > provided by the new API) way that can be used to stack plots composed by > many (>5k) points? I think a LineCollection may provide a very easy way to do what you want, if I understand correctly. I recently changed mri_with_eeg.py to use a LineCollection; maybe you are looking at an older version? Attached is the current version from svn. Eric > > Thanks > > Sébastien > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Sébastien / Seb-b. <seb...@gm...> - 2008-10-16 20:20:05
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Eric Firing wrote: > Sébastien / Seb-bubuntu wrote: [snip] > > I think a LineCollection may provide a very easy way to do what you > want, if I understand correctly. I recently changed mri_with_eeg.py to > use a LineCollection; maybe you are looking at an older version? > Attached is the current version from svn. > > Eric > [snip] Indeed my Matplotlib version is 0.98.1 (version from Ubuntu repos) so examples may be outdated. I'll try with your version (which seems much more simple). Thank you Sébastien -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFI96HqlabueleSRzIRAjVMAJ4qpR52lNdMp6aPB8WM8uXBjuD2UQCgqNzF FUc9rWqZaLPv1ZZ+DmApXbo= =/r2I -----END PGP SIGNATURE----- |