/tags/v0_70/matplotlib/examples/backend_driver.py

https://github.com/ericliang/matplotlib · Python · 124 lines · 112 code · 1 blank · 11 comment · 0 complexity · b2ed0a74a22cff199af662298bba6a9f MD5 · raw file

  1. #!/usr/bin/env python
  2. """
  3. This is use to drive many of the examples across the image backends
  4. and is used for regression testing and comparing backend efficiency
  5. This example creates a lot of temp files name _tmp_*.py. You'll
  6. probably want to remove them after the script runs
  7. """
  8. from __future__ import division
  9. import os, time
  10. files = (
  11. 'alignment_test.py',
  12. 'arctest.py',
  13. 'axes_demo.py',
  14. 'bar_stacked.py',
  15. 'barchart_demo.py',
  16. 'color_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. lines = [
  79. 'from __future__ import division\n',
  80. 'import matplotlib\n',
  81. 'matplotlib.use("%s")\n' % backend]
  82. print '\tdriving %s' % fname
  83. for line in file(fname):
  84. if line.strip().startswith('from __future__ import division'): continue
  85. if line.strip().startswith('matplotlib.use'): continue
  86. if line.strip().startswith('savefig'): continue
  87. if line.strip().startswith('show'): continue
  88. lines.append(line)
  89. basename, ext = os.path.splitext(fname)
  90. outfile = basename + '_%s'%backend
  91. if backend in ('GTK', 'WX', 'TkAgg'):
  92. lines.append('show()')
  93. else:
  94. lines.append('savefig("%s", dpi=150)' % outfile)
  95. tmpfile = '_tmp_%s.py' % basename
  96. file(tmpfile, 'w').write(''.join(lines))
  97. os.system('%s %s' % (python, tmpfile))
  98. times = {}
  99. #backends = ['Agg', 'Cairo', 'GDK', 'PS', 'SVG', 'Template']
  100. backends = ['Agg', 'PS', 'SVG', 'Template']
  101. #backends = [ 'GTK', 'WX', 'TkAgg']
  102. python = 'python2.3'
  103. for backend in backends:
  104. print 'testing %s' % backend
  105. t0 = time.time()
  106. drive(backend, python)
  107. t1 = time.time()
  108. times[backend] = (t1-t0)/60.0
  109. #print times
  110. for backend, elapsed in times.items():
  111. print 'Backend %s took %1.2f minutes to complete' % ( backend, elapsed)
  112. if 'Template' in times:
  113. print '\ttemplate ratio %1.3f, template residual %1.3f' % (
  114. elapsed/times['Template'], elapsed-times['Template'])