|
1 | 1 | """ |
2 | | -Use a PNG file as a watermark |
| 2 | +Use a Text as a watermark |
3 | 3 | """ |
4 | 4 | import numpy as np |
5 | 5 | import matplotlib |
6 | 6 | matplotlib.use('Agg') |
7 | 7 |
|
8 | | -import matplotlib.mathtext as mathtext |
9 | 8 | import matplotlib.pyplot as plt |
10 | | -import matplotlib |
11 | | -matplotlib.rc('image', origin='upper') |
12 | | - |
13 | | -dpi = 100 # save dpi |
14 | | -w, h = 8, 6 # inches |
15 | | - |
16 | | -parser = mathtext.MathTextParser("Bitmap") |
17 | 9 |
|
18 | | -rgba, depth1 = parser.to_rgba(r'Property of MPL', color='gray', |
19 | | - fontsize=30, dpi=200) |
20 | | -rgba[:,:,-1] *= 0.5 |
21 | | -fig = plt.figure(figsize=(w,h)) |
| 10 | +fig = plt.figure() |
22 | 11 |
|
23 | 12 | ax = fig.add_subplot(111) |
24 | 13 | ax.plot(np.random.rand(20), '-o', ms=20, lw=2, alpha=0.7, mfc='orange') |
25 | 14 | ax.grid() |
26 | 15 |
|
27 | | -imh, imw, tmp = rgba.shape |
28 | | - |
29 | | -# position image at bottom right |
30 | | -fig.figimage(rgba.astype(float)/255., w*dpi-imw, 0) |
31 | | - |
| 16 | +# position bottom right |
| 17 | +fig.text(0.95, 0.05, 'Property of MPL', |
| 18 | + fontsize=50, color='gray', |
| 19 | + ha='right', va='bottom', alpha=0.5) |
32 | 20 |
|
33 | | -fig.savefig('watermarked_text', transparent=True, dpi=dpi) |
| 21 | +fig.savefig('watermarked_text', transparent=True) |
34 | 22 |
|
0 commit comments