Skip to content

Commit 4889ab5

Browse files
authored
Merge pull request #170 from python-adaptive/add_logo
Add logo to the documentation
2 parents e1e3527 + 14d6942 commit 4889ab5

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

docs/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ help:
1414

1515
.PHONY: help Makefile
1616

17+
source/_static/logo_docs.png: logo.py
18+
python logo.py
19+
20+
# Fake target to avoid the catch-all target
21+
logo.py:
22+
@echo "never executed"
23+
1724
# Catch-all target: route all unknown targets to Sphinx using the new
1825
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19-
%: Makefile
26+
%: Makefile source/_static/logo_docs.png
2027
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/logo.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import sys
3+
4+
sys.path.insert(0, os.path.abspath('..')) # to get adaptive on the path
5+
6+
import adaptive
7+
import holoviews
8+
import matplotlib.pyplot as plt
9+
import matplotlib.tri as mtri
10+
from PIL import Image, ImageDraw
11+
holoviews.notebook_extension('matplotlib')
12+
13+
14+
def create_and_run_learner():
15+
def ring(xy):
16+
import numpy as np
17+
x, y = xy
18+
a = 0.2
19+
return x + np.exp(-(x**2 + y**2 - 0.75**2)**2/a**4)
20+
21+
learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])
22+
adaptive.runner.simple(learner, goal=lambda l: l.loss() < 0.01)
23+
return learner
24+
25+
26+
def plot_learner_and_save(learner, fname):
27+
fig, ax = plt.subplots()
28+
tri = learner.ip().tri
29+
triang = mtri.Triangulation(*tri.points.T, triangles=tri.vertices)
30+
ax.triplot(triang, c='k', lw=0.8)
31+
ax.imshow(learner.plot().Image.I.data, extent=(-0.5, 0.5, -0.5, 0.5))
32+
ax.set_xticks([])
33+
ax.set_yticks([])
34+
plt.savefig(fname, bbox_inches="tight", transparent=True, dpi=300, pad_inches=-0.1)
35+
36+
37+
def add_rounded_corners(fname, rad):
38+
im = Image.open(fname)
39+
circle = Image.new('L', (rad * 2, rad * 2), 0)
40+
draw = ImageDraw.Draw(circle)
41+
draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
42+
alpha = Image.new('L', im.size, 255)
43+
w, h = im.size
44+
alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
45+
alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
46+
alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
47+
alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
48+
im.putalpha(alpha)
49+
return im
50+
51+
52+
if __name__ == '__main__':
53+
learner = create_and_run_learner()
54+
fname = 'source/_static/logo_docs.png'
55+
plot_learner_and_save(learner, fname)
56+
im = add_rounded_corners(fname, rad=200)
57+
im.thumbnail((200, 200), Image.ANTIALIAS) # resize
58+
im.save(fname)

docs/source/_static/logo_docs.png

99.8 KB
Loading

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def get_holoviews_js_css():
145145
js, css = get_holoviews_js_css()
146146
html_context = {'holoviews_js_files': js} # used in source/_templates/layout.html
147147

148+
html_logo = 'logo_docs.png'
149+
148150

149151
def setup(app):
150152
for url in css:

0 commit comments

Comments
 (0)