|
2 | 2 | import sys, os, glob |
3 | 3 | import matplotlib |
4 | 4 | import IPython.Shell |
5 | | -matplotlib.rcdefaults() |
| 5 | +#matplotlib.rcdefaults() |
6 | 6 | matplotlib.use('Agg') |
7 | 7 |
|
8 | 8 | mplshell = IPython.Shell.MatplotlibShell('mpl') |
9 | 9 |
|
| 10 | +formats = [('png', 100), |
| 11 | + ('hires.png', 200), |
| 12 | + ('pdf', 72)] |
| 13 | + |
10 | 14 | def figs(): |
11 | 15 | print 'making figs' |
12 | 16 | import matplotlib.pyplot as plt |
13 | 17 | for fname in glob.glob('*.py'): |
14 | 18 | if fname.split('/')[-1] == __file__.split('/')[-1]: continue |
15 | 19 | basename, ext = os.path.splitext(fname) |
16 | | - outfile = '../_static/%s.png'%basename |
| 20 | + imagefiles = dict([('../_static/%s.%s'%(basename, format), dpi) |
| 21 | + for format, dpi in formats]) |
| 22 | + all_exists = True |
| 23 | + for imagefile in imagefiles: |
| 24 | + if not os.path.exists(imagefile): |
| 25 | + all_exists = False |
| 26 | + break |
17 | 27 |
|
18 | | - if os.path.exists(outfile): |
19 | | - print ' already have %s'%outfile |
20 | | - continue |
| 28 | + if all_exists: |
| 29 | + print ' already have %s'%fname |
21 | 30 | else: |
22 | 31 | print ' building %s'%fname |
23 | | - plt.close('all') # we need to clear between runs |
24 | | - mplshell.magic_run(basename) |
25 | | - plt.savefig(outfile) |
| 32 | + plt.close('all') # we need to clear between runs |
| 33 | + mplshell.magic_run(basename) |
| 34 | + for imagefile, dpi in imagefiles.iteritems(): |
| 35 | + plt.savefig(imagefile, dpi=dpi) |
26 | 36 | print 'all figures made' |
27 | 37 |
|
28 | 38 |
|
29 | 39 | def clean(): |
30 | | - patterns = ['#*', '*~', '*.png', '*pyc'] |
| 40 | + patterns = (['#*', '*~', '*pyc'] + |
| 41 | + ['*.%s' % format for format, dpi in formats]) |
31 | 42 | for pattern in patterns: |
32 | 43 | for fname in glob.glob(pattern): |
33 | 44 | os.remove(fname) |
|
0 commit comments