/tags/v0_73/matplotlib/examples/backend_driver.py

https://github.com/ericliang/matplotlib · Python · 131 lines · 109 code · 10 blank · 12 comment · 11 complexity · ca54b4b4bc30a38ce13829c3bb908652 MD5 · raw file

  1. #!/usr/bin/env python
  2. """
  3. This is used to drive many of the examples across the image backends,
  4. for regression testing, and comparing backend efficiency
  5. """
  6. from __future__ import division
  7. import os, time
  8. files = (
  9. 'alignment_test.py',
  10. 'arctest.py',
  11. 'axes_demo.py',
  12. 'bar_stacked.py',
  13. 'barchart_demo.py',
  14. 'color_demo.py',
  15. 'contour_demo.py',
  16. 'contourf_demo.py',
  17. 'csd_demo.py',
  18. 'custom_ticker1.py',
  19. 'customize_rc.py',
  20. 'date_demo1.py',
  21. 'date_demo2.py',
  22. 'figimage_demo.py',
  23. 'figlegend_demo.py',
  24. 'figtext.py',
  25. 'fill_demo.py',
  26. 'finance_demo.py',
  27. # 'fonts_demo_kw.py',
  28. 'histogram_demo.py',
  29. 'image_demo.py',
  30. 'image_demo2.py',
  31. 'image_demo_na.py',
  32. 'image_origin.py',
  33. 'invert_axes.py',
  34. 'layer_images.py',
  35. 'legend_demo.py',
  36. 'legend_demo2.py',
  37. 'line_styles.py',
  38. 'log_demo.py',
  39. 'log_test.py',
  40. 'major_minor_demo1.py',
  41. 'major_minor_demo2.py',
  42. 'mathtext_demo.py',
  43. 'mri_with_eeg.py',
  44. 'multiple_figs_demo.py',
  45. 'pcolor_demo.py',
  46. 'pcolor_demo2.py',
  47. 'pcolor_small.py',
  48. 'pie_demo.py',
  49. 'polar_demo.py',
  50. 'polar_scatter.py',
  51. 'psd_demo.py',
  52. 'scatter_demo.py',
  53. 'scatter_demo2.py',
  54. 'simple_plot.py',
  55. 'specgram_demo.py',
  56. 'stock_demo.py',
  57. 'subplot_demo.py',
  58. # 'set_and_get.py',
  59. 'table_demo.py',
  60. 'text_handles.py',
  61. 'text_rotation.py',
  62. 'text_themes.py',
  63. 'two_scales.py',
  64. 'vline_demo.py',
  65. 'zorder_demo.py',
  66. )
  67. #tests known to fail on python22 (require datetime)
  68. fail22 = (
  69. 'date_demo1.py',
  70. 'date_demo2.py',
  71. 'finance_demo.py',
  72. )
  73. def drive(backend, python='python2.3'):
  74. for fname in files:
  75. if python=='python2.2' and fname in fail22:
  76. print '\tSkipping %s, known to fail on python2.2'%fname
  77. continue
  78. print '\tdriving %s' % fname
  79. basename, ext = os.path.splitext(fname)
  80. outfile = basename + '_%s'%backend
  81. tmpfile_name = '_tmp_%s.py' % basename
  82. tmpfile = file(tmpfile_name, 'w')
  83. tmpfile.writelines((
  84. 'from __future__ import division\n',
  85. 'import matplotlib\n',
  86. 'matplotlib.use("%s")\n' % backend,
  87. ))
  88. for line in file(fname):
  89. line_lstrip = line.lstrip()
  90. if (line_lstrip.startswith('from __future__ import division') or
  91. line_lstrip.startswith('matplotlib.use') or
  92. line_lstrip.startswith('savefig') or
  93. line_lstrip.startswith('show')):
  94. continue
  95. tmpfile.write(line)
  96. if backend in ('GTK', 'WX', 'TkAgg'):
  97. tmpfile.write('show()')
  98. else:
  99. tmpfile.write('savefig("%s", dpi=150)' % outfile)
  100. tmpfile.close()
  101. os.system('%s %s' % (python, tmpfile_name))
  102. os.remove(tmpfile_name)
  103. if __name__ == '__main__':
  104. times = {}
  105. # backends = ['Agg', 'Cairo', 'GDK', 'PS', 'SVG', 'Template']
  106. backends = ['Agg', 'PS', 'SVG', 'Template']
  107. # backends = [ 'GTK', 'WX', 'TkAgg']
  108. # backends = ['PS']
  109. python = 'python2.3'
  110. for backend in backends:
  111. print 'testing %s' % backend
  112. t0 = time.time()
  113. drive(backend, python)
  114. t1 = time.time()
  115. times[backend] = (t1-t0)/60.0
  116. # print times
  117. for backend, elapsed in times.items():
  118. print 'Backend %s took %1.2f minutes to complete' % ( backend, elapsed)
  119. if 'Template' in times:
  120. print '\ttemplate ratio %1.3f, template residual %1.3f' % (
  121. elapsed/times['Template'], elapsed-times['Template'])