/tags/v0_60_2/htdocs/examples/backend_driver.py

https://github.com/ericliang/matplotlib · Python · 107 lines · 95 code · 1 blank · 11 comment · 0 complexity · 1f1a839e085e07f0f3f202894f968d9d 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. 'psd_demo.py',
  49. 'scatter_demo.py',
  50. 'scatter_demo2.py',
  51. 'simple_plot.py',
  52. 'specgram_demo.py',
  53. 'stock_demo.py',
  54. 'subplot_demo.py',
  55. 'table_demo.py',
  56. 'text_handles.py',
  57. 'text_themes.py',
  58. 'two_scales.py',
  59. 'vline_demo.py',
  60. )
  61. def drive(backend):
  62. for fname in files:
  63. lines = [
  64. 'from __future__ import division\n',
  65. 'import matplotlib\n',
  66. 'matplotlib.use("%s")\n' % backend]
  67. print '\tdriving %s' % fname
  68. for line in file(fname):
  69. if line.strip().startswith('from __future__ import division'): continue
  70. if line.strip().startswith('matplotlib.use'): continue
  71. if line.strip().startswith('savefig'): continue
  72. if line.strip().startswith('show'): continue
  73. lines.append(line)
  74. basename, ext = os.path.splitext(fname)
  75. outfile = basename + '_%s'%backend
  76. if backend in ('GTK', 'WX', 'TkAgg'):
  77. lines.append('show()')
  78. else:
  79. lines.append('savefig("%s", dpi=150)' % outfile)
  80. tmpfile = '_tmp_%s.py' % basename
  81. file(tmpfile, 'w').write(''.join(lines))
  82. os.system('python %s' % tmpfile)
  83. times = {}
  84. backends = ['PS', 'GD', 'Paint', 'Agg', 'Template']
  85. #backends.extend([ 'GTK', 'WX', 'TkAgg'])
  86. backends = [ 'SVG']
  87. #backends = [ 'Agg', 'PS', 'Template']
  88. for backend in backends:
  89. print 'testing %s' % backend
  90. t0 = time.time()
  91. drive(backend)
  92. t1 = time.time()
  93. times[backend] = (t1-t0)/60.0
  94. #print times
  95. for backend, elapsed in times.items():
  96. print 'Backend %s took %1.2f minutes to complete' % ( backend, elapsed)
  97. print '\ttemplate ratio %1.3f, template residual %1.3f' % (
  98. elapsed/times['Template'], elapsed-times['Template'])