Skip to content

Commit

Permalink
Merge pull request #170 from python-adaptive/add_logo
Browse files Browse the repository at this point in the history
Add logo to the documentation
  • Loading branch information
jbweston authored Apr 8, 2019
2 parents e1e3527 + 14d6942 commit 4889ab5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ help:

.PHONY: help Makefile

source/_static/logo_docs.png: logo.py
python logo.py

# Fake target to avoid the catch-all target
logo.py:
@echo "never executed"

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
%: Makefile source/_static/logo_docs.png
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
58 changes: 58 additions & 0 deletions docs/logo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import sys

sys.path.insert(0, os.path.abspath('..')) # to get adaptive on the path

import adaptive
import holoviews
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
from PIL import Image, ImageDraw
holoviews.notebook_extension('matplotlib')


def create_and_run_learner():
def ring(xy):
import numpy as np
x, y = xy
a = 0.2
return x + np.exp(-(x**2 + y**2 - 0.75**2)**2/a**4)

learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])
adaptive.runner.simple(learner, goal=lambda l: l.loss() < 0.01)
return learner


def plot_learner_and_save(learner, fname):
fig, ax = plt.subplots()
tri = learner.ip().tri
triang = mtri.Triangulation(*tri.points.T, triangles=tri.vertices)
ax.triplot(triang, c='k', lw=0.8)
ax.imshow(learner.plot().Image.I.data, extent=(-0.5, 0.5, -0.5, 0.5))
ax.set_xticks([])
ax.set_yticks([])
plt.savefig(fname, bbox_inches="tight", transparent=True, dpi=300, pad_inches=-0.1)


def add_rounded_corners(fname, rad):
im = Image.open(fname)
circle = Image.new('L', (rad * 2, rad * 2), 0)
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
alpha = Image.new('L', im.size, 255)
w, h = im.size
alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
im.putalpha(alpha)
return im


if __name__ == '__main__':
learner = create_and_run_learner()
fname = 'source/_static/logo_docs.png'
plot_learner_and_save(learner, fname)
im = add_rounded_corners(fname, rad=200)
im.thumbnail((200, 200), Image.ANTIALIAS) # resize
im.save(fname)
Binary file added docs/source/_static/logo_docs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def get_holoviews_js_css():
js, css = get_holoviews_js_css()
html_context = {'holoviews_js_files': js} # used in source/_templates/layout.html

html_logo = 'logo_docs.png'


def setup(app):
for url in css:
Expand Down

0 comments on commit 4889ab5

Please sign in to comment.