Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Matplotlib_test_with_set_lim

By: a guest on Jan 24th, 2013  |  syntax: Python  |  size: 1.49 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import numpy as np
  2. import matplotlib.pyplot as pl
  3. import pdb
  4.  
  5. def plotData(data, options='', limits=[]):
  6.     group_colors = []      
  7.     for i,dset in enumerate(data):
  8.         x = np.array([point['x'] for point in dset])
  9.         y = np.array([-point['y'] for point in dset])
  10.         if options != '':
  11.             pl.plot(x,y,options)
  12.         else:
  13.             pl.plot(x,y)
  14.         pl.hold(True)
  15.         pl.annotate(str(i), xy = (x[0],y[0]))
  16.     if len(limits):
  17.         pl.gca().set_xlim(limits[0],limits[1])
  18.         pl.gca().set_ylim(limits[2],limits[3])        
  19.  
  20. def testPlot():
  21.     colors = ['b','g','r','c','m','k','y']
  22.     data1 = [[dict(x=1,y=1),dict(x=2,y=2),dict(x=3,y=3)],[dict(x=2,y=2),dict(x=4,y=4)],[dict(x=5,y=5),dict(x=6,y=8)]]
  23.     data2 = [[dict(x=1,y=1),dict(x=2,y=2),dict(x=3,y=3)],[dict(x=2,y=2),dict(x=4,y=4)]]
  24.     data = []
  25.     data.append(data1)
  26.     data.append(data2)
  27.     data.append(data1)
  28.     pl.figure()
  29.     pl.ion()
  30.     pl.subplot(2,1,1)
  31.     # Title with best definition from dictionary
  32.     pl.title("Title on top")
  33.     # Plot the data but colored according to segmentation in top plot
  34.     for i in range(len(data1)):
  35.         plotData([data1[i]],colors[i%len(colors)])
  36.     # Then plot segmentation parts (radicals) in different corresponding colors
  37.     # Title each plot with radical names
  38.     for i in range(len(data)):
  39.         pl.subplot(2,3,4+i)
  40.         pl.title("Row 2 subplot {0}".format(i))
  41.         plotData(data[i],colors[i%len(colors)],[0, 15, 0, 15])