Function iaplot - Plotting function - ready for display by adshow

Synopse

Plot a list of the 1D-NumPy arrays contained in Xlist against the list of 1D-NumPy arrays contained in Ylist. The method returns an image ready to be displayed by adshow.

  • img = iaplot(Ylist, Xlist = [], arrows_list = [],text_list = [], ylabel='y', xlabel'x', title='',colors = 'rgbmyc',shapes = '------', axis = 'tight')
    • Output
      • img: 2d-array, image ready to be displayed by adshow
    • Input
      • Ylist: list of 1D numpy arrays y coordinates
      • Xlist: list of 1D numpy arrays x coordinates
      • arrows_list: list of arrorws coordinates. Example: [[x1,y1,dx1,dy1],[x2,y2,dx2,dy2]]
      • text_list: list containing text to be annotated. Example: [['Max',x1,y1],['Min',x2,y2]]
      • ylabel: optional, string for ordinate field
      • xlabel: optional, string for abscissa field
      • title: optional, string for title field
      • colors: optional, string withe the colors of the plots
      • shapes: optional, string with the shapes to be used in the plots. Example: shapes = "*xo^<>v+s-"
      • axis: optional, string containing the axis option: 'tight' or 'equal'

Description

iaplot plots a list of the 1D-NumPy arrays contained in Xlist against the list of 1D-NumPy arrays contained in Ylist using different colors. If Xlist is empty, then it will range(len(Ylist[i])) vs Ylist[i]. The color convention is the same using in iagshow: red, green, blue, magenta, yellow and cyan. The output array is ready for display using adshow.

Function Code

01. def iaplot(Ylist, Xlist = [], arrows_list = [],text_list = [], ylabel='y', xlabel='x', title='',colors = 'rgbmycrgbm',shapes = '----------', axis = 'tight'):
02.     import numpy as np
03.     import matplotlib
04.     matplotlib.use('Agg')
05.     import matplotlib.pyplot as plt
06.     import ia636
07. 
08.     if isinstance(Ylist, np.ndarray):
09.         Ylist = [Ylist]
10.     if  Xlist == []:
11.        Xlist = [np.arange(len(i)) for i in Ylist]
12.     if isinstance(Xlist, np.ndarray):
13.         Xlist = [Xlist]
14. 
15.     fig = plt.figure()
16.     plt.ylabel(ylabel)
17.     plt.xlabel(xlabel)
18.     plt.title(title)
19.     for x,y, c,s in zip(Xlist, Ylist,colors[:len(Xlist)],shapes[:len(Xlist)]):
20.         plt.plot(x,y, c+s,markersize=9)
21. 
22.     for arrow in arrows_list:
23.         plt.arrow(arrow[0], arrow[1], arrow[2], arrow[3], fc="k", ec="k", head_width=0.15, head_length=0.2 )
24. 
25.     for text in text_list:
26.         plt.annotate(text[0],xy=(text[1], text[2]), xycoords='data',xytext=(text[1], text[2]), textcoords='data',)
27.     plt.grid()
28.     plt.axis(axis)
29.     return ia636.iafig2img(fig)

Simple plottings:

1. import ia636 as ia
2. 
3. adshow(ia.iaplot(arange(256)))
4. 
5. adshow(ia.iaplot([arange(256), arange(0,256,2)]))
6. 
7. adshow(ia.iaplot([arange(256), arange(0,256,2), arange(0,512,3)]))
8. 
9. adshow(ia.iaplot([arange(256), arange(0,256,2), arange(0,512,3), arange(-100,300)]))

Multiple plots with explicit x

1. import ia636 as ia
2. 
3. x1 = linspace(-pi,pi,50)
4. x2 = linspace(-pi,pi,60)
5. Xlist = [x1,x2]
6. y1 = cos(x1)
7. y2 = sin(x2)
8. Ylist = [y1,y2]
9. adshow(ia.iaplot(Ylist,Xlist,shapes='xo'))

Example 02: Plots with arrows

1. x1 = linspace(0,2*pi,50)
2. y1  = cos(x1)
3. arrows_list = [[pi-1,-0.9,0.3,0],[2*pi -1,0.9,0.3,0]]
4. adshow(ia.iaplot(y1,x1,arrows_list))

Example 03: Plots with arrows and text

1. x1 = linspace(0,2*pi,50)
2. y1  = cos(x1)
3. arrows_list = [[pi-1,-0.9,0.3,0],[2*pi -1,0.9,0.3,0]]
4. text_list = [['pt1',pi-1.5,-0.9],['pt2',2*pi -1.5,0.9,0.3,0]]
5. adshow(ia.iaplot(y1,x1,arrows_list,text_list))

Example 04: Plots with markers

1. x = list(arange(20).reshape(10,2))
2. adshow(ia.iaplot(x,x, shapes = "*xo^<>v+s-", colors = 'rgbmycrgbm'))
3. adshow(ia.iaplot(x,x, shapes = "v+s-*xo^<>"))

See Also

  • ia636:iafig2img - generate output from matplotlib ready for display by adshow

References

Contributions

  • Roberto Souza, 02oct2013: more features
  • André Luis da Costa, 24aug2013: initial function
  • Roberto Lotufo, 24aug2013: insertion in ia636.