forked from matplotlib/cheatsheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtip-post-processing.py
27 lines (24 loc) · 1.01 KB
/
tip-post-processing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvas
from scipy.ndimage import gaussian_filter
# First pass for drop-shadow
fig = Figure(figsize=(6,1.5))
canvas = FigureCanvas(fig)
ax = fig.add_axes([0,0,1,1], frameon=False,
xlim=[0,1], xticks=[], ylim=[0,1], yticks=[])
ax.text(0.5, 0.5, "Matplotlib", transform=ax.transAxes,
ha="center", va="center", size=64, color="black")
canvas.draw()
Z = np.array(canvas.renderer.buffer_rgba())[:,:,0]
Z = gaussian_filter(Z, sigma=9)
# Second pass for text + drop-shadow
fig = plt.figure(figsize=(6,1.5))
ax = fig.add_axes([0,0,1,1], frameon=False,
xlim=[0,1], xticks=[], ylim=[0,1], yticks=[])
ax.imshow(Z, extent=[0,1,0,1], cmap=plt.cm.gray, alpha=0.65, aspect='auto')
ax.text(0.5, 0.5, "Matplotlib", transform=ax.transAxes,
ha="center", va="center", size=64, color="black")
plt.savefig("../figures/tip-post-processing.pdf", dpi=600)
# plt.show()