pylab.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. """
  2. This is a procedural interface to the matplotlib object-oriented
  3. plotting library.
  4. The following plotting commands are provided; the majority have
  5. MATLAB |reg| [*]_ analogs and similar arguments.
  6. .. |reg| unicode:: 0xAE
  7. _Plotting commands
  8. acorr - plot the autocorrelation function
  9. annotate - annotate something in the figure
  10. arrow - add an arrow to the axes
  11. axes - Create a new axes
  12. axhline - draw a horizontal line across axes
  13. axvline - draw a vertical line across axes
  14. axhspan - draw a horizontal bar across axes
  15. axvspan - draw a vertical bar across axes
  16. axis - Set or return the current axis limits
  17. autoscale - turn axis autoscaling on or off, and apply it
  18. bar - make a bar chart
  19. barh - a horizontal bar chart
  20. broken_barh - a set of horizontal bars with gaps
  21. box - set the axes frame on/off state
  22. boxplot - make a box and whisker plot
  23. violinplot - make a violin plot
  24. cla - clear current axes
  25. clabel - label a contour plot
  26. clf - clear a figure window
  27. clim - adjust the color limits of the current image
  28. close - close a figure window
  29. colorbar - add a colorbar to the current figure
  30. cohere - make a plot of coherence
  31. contour - make a contour plot
  32. contourf - make a filled contour plot
  33. csd - make a plot of cross spectral density
  34. delaxes - delete an axes from the current figure
  35. draw - Force a redraw of the current figure
  36. errorbar - make an errorbar graph
  37. figlegend - make legend on the figure rather than the axes
  38. figimage - make a figure image
  39. figtext - add text in figure coords
  40. figure - create or change active figure
  41. fill - make filled polygons
  42. findobj - recursively find all objects matching some criteria
  43. gca - return the current axes
  44. gcf - return the current figure
  45. gci - get the current image, or None
  46. getp - get a graphics property
  47. grid - set whether gridding is on
  48. hist - make a histogram
  49. ioff - turn interaction mode off
  50. ion - turn interaction mode on
  51. isinteractive - return True if interaction mode is on
  52. imread - load image file into array
  53. imsave - save array as an image file
  54. imshow - plot image data
  55. legend - make an axes legend
  56. locator_params - adjust parameters used in locating axis ticks
  57. loglog - a log log plot
  58. matshow - display a matrix in a new figure preserving aspect
  59. margins - set margins used in autoscaling
  60. pause - pause for a specified interval
  61. pcolor - make a pseudocolor plot
  62. pcolormesh - make a pseudocolor plot using a quadrilateral mesh
  63. pie - make a pie chart
  64. plot - make a line plot
  65. plot_date - plot dates
  66. plotfile - plot column data from an ASCII tab/space/comma delimited file
  67. pie - pie charts
  68. polar - make a polar plot on a PolarAxes
  69. psd - make a plot of power spectral density
  70. quiver - make a direction field (arrows) plot
  71. rc - control the default params
  72. rgrids - customize the radial grids and labels for polar
  73. savefig - save the current figure
  74. scatter - make a scatter plot
  75. setp - set a graphics property
  76. semilogx - log x axis
  77. semilogy - log y axis
  78. show - show the figures
  79. specgram - a spectrogram plot
  80. spy - plot sparsity pattern using markers or image
  81. stem - make a stem plot
  82. subplot - make one subplot (numrows, numcols, axesnum)
  83. subplots - make a figure with a set of (numrows, numcols) subplots
  84. subplots_adjust - control the subplot positions of current figure
  85. subplot_tool - launch the subplot configuration tool
  86. suptitle - add a figure title
  87. table - add a table to the plot
  88. text - add some text at location (x, y) to the current axes
  89. thetagrids - customize the radial theta grids and labels for polar
  90. tick_params - control the appearance of ticks and tick labels
  91. ticklabel_format - control the format of tick labels
  92. title - add a title to the current axes
  93. tricontour - make a contour plot on a triangular grid
  94. tricontourf - make a filled contour plot on a triangular grid
  95. tripcolor - make a pseudocolor plot on a triangular grid
  96. triplot - plot a triangular grid
  97. xcorr - plot the autocorrelation function of x and y
  98. xlim - set/get the xlimits
  99. ylim - set/get the ylimits
  100. xticks - set/get the xticks
  101. yticks - set/get the yticks
  102. xlabel - add an xlabel to the current axes
  103. ylabel - add a ylabel to the current axes
  104. autumn - set the default colormap to autumn
  105. bone - set the default colormap to bone
  106. cool - set the default colormap to cool
  107. copper - set the default colormap to copper
  108. flag - set the default colormap to flag
  109. gray - set the default colormap to gray
  110. hot - set the default colormap to hot
  111. hsv - set the default colormap to hsv
  112. jet - set the default colormap to jet
  113. pink - set the default colormap to pink
  114. prism - set the default colormap to prism
  115. spring - set the default colormap to spring
  116. summer - set the default colormap to summer
  117. winter - set the default colormap to winter
  118. _Event handling
  119. connect - register an event handler
  120. disconnect - remove a connected event handler
  121. _Matrix commands
  122. cumprod - the cumulative product along a dimension
  123. cumsum - the cumulative sum along a dimension
  124. detrend - remove the mean or besdt fit line from an array
  125. diag - the k-th diagonal of matrix
  126. diff - the n-th difference of an array
  127. eig - the eigenvalues and eigen vectors of v
  128. eye - a matrix where the k-th diagonal is ones, else zero
  129. find - return the indices where a condition is nonzero
  130. fliplr - flip the rows of a matrix up/down
  131. flipud - flip the columns of a matrix left/right
  132. linspace - a linear spaced vector of N values from min to max inclusive
  133. logspace - a log spaced vector of N values from min to max inclusive
  134. meshgrid - repeat x and y to make regular matrices
  135. ones - an array of ones
  136. rand - an array from the uniform distribution [0, 1]
  137. randn - an array from the normal distribution
  138. rot90 - rotate matrix k*90 degrees counterclockwise
  139. squeeze - squeeze an array removing any dimensions of length 1
  140. tri - a triangular matrix
  141. tril - a lower triangular matrix
  142. triu - an upper triangular matrix
  143. vander - the Vandermonde matrix of vector x
  144. svd - singular value decomposition
  145. zeros - a matrix of zeros
  146. _Probability
  147. rand - random numbers from the uniform distribution
  148. randn - random numbers from the normal distribution
  149. _Statistics
  150. amax - the maximum along dimension m
  151. amin - the minimum along dimension m
  152. corrcoef - correlation coefficient
  153. cov - covariance matrix
  154. mean - the mean along dimension m
  155. median - the median along dimension m
  156. norm - the norm of vector x
  157. prod - the product along dimension m
  158. ptp - the max-min along dimension m
  159. std - the standard deviation along dimension m
  160. asum - the sum along dimension m
  161. ksdensity - the kernel density estimate
  162. _Time series analysis
  163. bartlett - M-point Bartlett window
  164. blackman - M-point Blackman window
  165. cohere - the coherence using average periodogram
  166. csd - the cross spectral density using average periodogram
  167. fft - the fast Fourier transform of vector x
  168. hamming - M-point Hamming window
  169. hanning - M-point Hanning window
  170. hist - compute the histogram of x
  171. kaiser - M length Kaiser window
  172. psd - the power spectral density using average periodogram
  173. sinc - the sinc function of array x
  174. _Dates
  175. date2num - convert python datetimes to numeric representation
  176. drange - create an array of numbers for date plots
  177. num2date - convert numeric type (float days since 0001) to datetime
  178. _Other
  179. angle - the angle of a complex array
  180. load - Deprecated--please use loadtxt.
  181. loadtxt - load ASCII data into array.
  182. polyfit - fit x, y to an n-th order polynomial
  183. polyval - evaluate an n-th order polynomial
  184. roots - the roots of the polynomial coefficients in p
  185. save - Deprecated--please use savetxt.
  186. savetxt - save an array to an ASCII file.
  187. trapz - trapezoidal integration
  188. __end
  189. .. [*] MATLAB is a registered trademark of The MathWorks, Inc.
  190. """
  191. from matplotlib.cbook import flatten, silent_list, iterable, dedent
  192. import matplotlib as mpl
  193. from matplotlib.dates import (
  194. date2num, num2date, datestr2num, strpdate2num, drange, epoch2num,
  195. num2epoch, mx2num, DateFormatter, IndexDateFormatter, DateLocator,
  196. RRuleLocator, YearLocator, MonthLocator, WeekdayLocator, DayLocator,
  197. HourLocator, MinuteLocator, SecondLocator, rrule, MO, TU, WE, TH, FR,
  198. SA, SU, YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY,
  199. relativedelta)
  200. # bring all the symbols in so folks can import them from
  201. # pylab in one fell swoop
  202. ## We are still importing too many things from mlab; more cleanup is needed.
  203. from matplotlib.mlab import (
  204. demean, detrend, detrend_linear, detrend_mean, detrend_none,
  205. window_hanning, window_none)
  206. from matplotlib import cbook, mlab, pyplot as plt
  207. from matplotlib.pyplot import *
  208. from numpy import *
  209. from numpy.fft import *
  210. from numpy.random import *
  211. from numpy.linalg import *
  212. import numpy as np
  213. import numpy.ma as ma
  214. # don't let numpy's datetime hide stdlib
  215. import datetime
  216. # This is needed, or bytes will be numpy.random.bytes from
  217. # "from numpy.random import *" above
  218. bytes = __import__("builtins").bytes