Code Search for Developers
 
 
  

mri_with_eeg.py from matplotlib at Krugle


Show mri_with_eeg.py syntax highlighted

#!/usr/bin/env python
"""
This now uses the imshow command instead of pcolor which *is much
faster*
"""
from __future__ import division
from pylab import *
from matplotlib.lines import Line2D
from matplotlib.transforms import get_bbox_transform, Point, Value, Bbox,\
     unit_bbox

# I use if 1 to break up the different regions of code visually

if 1:   # load the data
    # data are 256x256 16 bit integers
    dfile = 'data/s1045.ima'
    im = fromstring(file(dfile, 'rb').read(), UInt16).astype(Float)
    im.shape = 256, 256

if 1: # plot the MRI in pcolor
    subplot(221)
    imshow(im)
    axis('off')

if 1:  # plot the histogram of MRI intensity
    subplot(222)
    im = ravel(im)
    im = take(im, nonzero(im)) # ignore the background
    im = im/(2.0**15) # normalize
    hist(im, 100)
    xticks([])
    yticks([])
    xlabel('intensity')
    ylabel('MRI density')

if 1:   # plot the EEG
    # load the data
    numSamples, numRows = 800,4
    data = fromstring(file('data/eeg.dat', 'rb').read(), Float)
    data.shape = numSamples, numRows
    t = arange(numSamples)/float(numSamples)*10.0
    ticklocs = []
    ax = subplot(212)

    boxin = Bbox(
        Point(ax.viewLim.ll().x(), Value(-20)),
        Point(ax.viewLim.ur().x(), Value(20)))


    height = ax.bbox.ur().y() - ax.bbox.ll().y()
    boxout = Bbox(
        Point(ax.bbox.ll().x(), Value(-1)*height),
        Point(ax.bbox.ur().x(), Value(1) * height))


    transOffset = get_bbox_transform(
        unit_bbox(),
        Bbox( Point( Value(0), ax.bbox.ll().y()),
              Point( Value(1), ax.bbox.ur().y())
              ))


    for i in range(numRows):
        # effectively a copy of transData
        trans = get_bbox_transform(boxin, boxout) 
        offset = (i+1)/(numRows+1)

        trans.set_offset( (0, offset), transOffset)
        
        thisLine = Line2D(
            t, data[:,i]-data[0,i],
            )
        
        thisLine.set_transform(trans)
        
        ax.add_line(thisLine)
        ticklocs.append(offset)

    xlim(0,10)
    xticks(arange(10))

    yticks(ticklocs, ['PG3', 'PG5', 'PG7', 'PG9'])

    # set the yticks to use axes coords on the y axis
    ax.set_yticks(ticklocs)
    for tick in ax.yaxis.get_major_ticks():
        tick.label1.set_transform(ax.transAxes)
        tick.label2.set_transform(ax.transAxes)        
        tick.tick1line.set_transform(ax.transAxes)
        tick.tick2line.set_transform(ax.transAxes)        
        tick.gridline.set_transform(ax.transAxes)                


    xlabel('time (s)')

show()




See more files for this project here

matplotlib

Matplotlib is a pure python plotting library with the goal of making\r\npublication quality plots using a syntax familiar to matlab users. \r\nThe library uses Numeric for handling large\r\ndata sets and supports a variety of output backends

Project homepage: http://sourceforge.net/projects/matplotlib
Programming language(s): C,C++,Python
License: other

  data/
    500hgtdata.gz
    500hgtlats.gz
    500hgtlons.gz
    chandra.dat
    eeg.dat
    etopo20data.gz
    etopo20lats.gz
    etopo20lons.gz
    hst.zdat
    intc.csv
    msft.csv
    s1045.ima
  __init__.py
  align_text.py
  align_text_large.png
  align_text_small.png
  alignment_test.py
  axes_demo.py
  axes_demo_large.png
  axes_demo_small.png
  barchart_demo.py
  barchart_demo_large.png
  barchart_demo_small.png
  colours.py
  contour_shot.py
  contour_small.png
  data_helper.py
  date_demo.py
  date_demo_large.png
  date_demo_small.png
  eeg.py
  eeg_large.png
  eeg_small.png
  etopo20data.gz
  etopo20lats.gz
  etopo20lons.gz
  fill_demo.py
  fill_demo_large.png
  fill_demo_small.png
  finance_work2.py
  finance_work2_large.png
  finance_work2_small.png
  helpers.py
  histogram_demo.py
  histogram_demo_large.png
  histogram_demo_small.png
  hstdemo.py
  layer_images.py
  layer_images_large.png
  layer_images_small.png
  legend_demo.py
  legend_demo_large.png
  legend_demo_small.png
  log_shot.png
  log_shot.py
  log_shot_large.png
  log_shot_small.png
  logo.png
  makeshots.py
  mathtext_demo.py
  mathtext_demo_large.png
  mathtext_demo_small.png
  matplotlibrc
  mri_demo.py
  mri_with_eeg.py
  mri_with_eeg_large.png
  mri_with_eeg_small.png
  msft_nasdaq_d.csv
  pcolor_demo.py
  pcolor_demo_large.png
  pcolor_demo_small.png
  pfm-lsm.png
  pie_demo.py
  pie_demo_large.png
  pie_demo_small.png
  plotmap.py
  plotmap_large.png
  plotmap_small.png
  polar_demo.py
  polar_demo_large.png
  polar_demo_small.png
  proj.py
  scatter_demo2.py
  scatter_demo2_large.png
  scatter_demo2_small.png
  simple_plot.py
  simple_plot_large.png
  simple_plot_small.png
  slider_demo.py
  slider_demo_large.png
  slider_demo_small.png
  subplot_demo.py
  subplot_demo_large.png
  subplot_demo_small.png
  table_demo.py
  table_demo_large.png
  table_demo_small.png
  tex_demo.py
  tex_demo_large.png
  tex_demo_small.png
  text_themes.py
  text_themes_large.png
  text_themes_small.png
  wheeler_demo.py
  wheeler_demo_large.png
  wheeler_demo_small.png