Skip to content

Commit 751ed36

Browse files
committed
notebook-based infrastructure
1 parent 68bc9fa commit 751ed36

File tree

15 files changed

+2922
-20
lines changed

15 files changed

+2922
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ coverage.xml
5353

5454
# Sphinx documentation
5555
docs/_build/
56+
.ipynb_checkpoints
57+
docs/tutorial/*.rst
58+
docs/tutorial/*_files/
5659

5760
# PyBuilder
5861
target/

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ Simply importing `probscale` lets you use probability scales in your matplotlib
99
```python
1010
import matplotlib.pyplot as plt
1111
import probscale
12+
import seaborn
13+
clear_bkgd = {'axes.facecolor':'none', 'figure.facecolor':'none'}
14+
seaborn.set(style='ticks', context='notebook', rc=clear_bkgd)
1215

13-
plt.style.use('ggplot')
1416
fig, ax = plt.subplots(figsize=(8, 4))
1517
ax.set_ylim(1e-2, 1e2)
1618
ax.set_yscale('log')
1719

1820
ax.set_xlim(0.5, 99.5)
1921
ax.set_xscale('prob')
22+
seaborn.despine(fig=fig)
2023
```
2124

2225
![Alt text](docs/img/example.png "Example axes")

docs/conf.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@
2828
# If your documentation needs a minimal Sphinx version, state it here.
2929
#needs_sphinx = '1.0'
3030

31-
from recommonmark.parser import CommonMarkParser
32-
33-
source_parsers = {
34-
'.md': CommonMarkParser,
35-
}
36-
37-
source_suffix = ['.rst', '.md']
31+
source_suffix = ['.rst']
3832

3933
numpydoc_show_class_members = False
4034
autodoc_member_order = 'bysource'
@@ -43,14 +37,19 @@
4337
# Add any Sphinx extension module names here, as strings. They can be
4438
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4539
# ones.
40+
sys.path.insert(0, os.path.abspath('sphinxext'))
4641
extensions = [
4742
'sphinx.ext.autodoc',
4843
'sphinx.ext.doctest',
4944
'sphinx.ext.intersphinx',
5045
'sphinx.ext.todo',
5146
'sphinx.ext.mathjax',
5247
'sphinx.ext.viewcode',
48+
'plot_generator',
49+
'plot_directive',
5350
'numpydoc',
51+
'ipython_directive',
52+
'ipython_console_highlighting',
5453
]
5554

5655
# Add any paths that contain templates here, relative to this directory.

docs/examples/index.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
3+
.. raw:: html
4+
5+
<style type="text/css">
6+
.figure {
7+
position: relative;
8+
float: left;
9+
margin: 10px;
10+
width: 180px;
11+
height: 200px;
12+
}
13+
14+
.figure img {
15+
position: absolute;
16+
display: inline;
17+
left: 0;
18+
width: 170px;
19+
height: 170px;
20+
opacity:1.0;
21+
filter:alpha(opacity=100); /* For IE8 and earlier */
22+
}
23+
24+
.figure:hover img {
25+
-webkit-filter: blur(3px);
26+
-moz-filter: blur(3px);
27+
-o-filter: blur(3px);
28+
-ms-filter: blur(3px);
29+
filter: blur(3px);
30+
opacity:1.0;
31+
filter:alpha(opacity=100); /* For IE8 and earlier */
32+
}
33+
34+
.figure span {
35+
position: absolute;
36+
display: inline;
37+
left: 0;
38+
width: 170px;
39+
height: 170px;
40+
background: #000;
41+
color: #fff;
42+
visibility: hidden;
43+
opacity: 0;
44+
z-index: 100;
45+
}
46+
47+
.figure p {
48+
position: absolute;
49+
top: 45%;
50+
width: 170px;
51+
font-size: 110%;
52+
}
53+
54+
.figure:hover span {
55+
visibility: visible;
56+
opacity: .4;
57+
}
58+
59+
.caption {
60+
position: absolue;
61+
width: 180px;
62+
top: 170px;
63+
text-align: center !important;
64+
}
65+
</style>
66+
67+
.. _example_gallery:
68+
69+
Example gallery
70+
===============
71+
72+
73+
74+
.. toctree::
75+
:hidden:
76+
77+
78+
79+
80+
81+
82+
83+
.. raw:: html
84+
85+
<div style="clear: both"></div>

docs/img/example.png

-6.76 KB
Loading

docs/index.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,40 @@ Simply importing ``probscale`` lets you use probability scales in your matplotli
2121
2222
import matplotlib.pyplot as plt
2323
import probscale
24+
import seaborn
25+
clear_bkgd = {'axes.facecolor':'none', 'figure.facecolor':'none'}
26+
seaborn.set(style='ticks', context='notebook', rc=clear_bkgd)
2427
25-
plt.style.use('ggplot')
2628
fig, ax = plt.subplots(figsize=(8, 4))
2729
ax.set_ylim(1e-2, 1e2)
2830
ax.set_yscale('log')
2931
3032
ax.set_xlim(0.5, 99.5)
3133
ax.set_xscale('prob')
34+
seaborn.despine(fig=fig)
3235
3336
3437
.. image:: /img/example.png
3538

3639

40+
Tutorial
41+
--------
42+
43+
.. toctree::
44+
:maxdepth: 2
45+
46+
tutorial/getting_started.rst
47+
3748
API References
38-
==============
49+
--------------
3950

4051
.. toctree::
4152
:maxdepth: 2
4253

54+
probscale.rst
4355
viz.rst
4456

45-
probscale.rst
57+
4658

4759

4860
Indices and tables
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"""reST directive for syntax-highlighting ipython interactive sessions.
2+
3+
XXX - See what improvements can be made based on the new (as of Sept 2009)
4+
'pycon' lexer for the python console. At the very least it will give better
5+
highlighted tracebacks.
6+
"""
7+
8+
#-----------------------------------------------------------------------------
9+
# Needed modules
10+
11+
# Standard library
12+
import re
13+
14+
# Third party
15+
from pygments.lexer import Lexer, do_insertions
16+
from pygments.lexers.agile import (PythonConsoleLexer, PythonLexer,
17+
PythonTracebackLexer)
18+
from pygments.token import Comment, Generic
19+
20+
from sphinx import highlighting
21+
22+
#-----------------------------------------------------------------------------
23+
# Global constants
24+
line_re = re.compile('.*?\n')
25+
26+
#-----------------------------------------------------------------------------
27+
# Code begins - classes and functions
28+
29+
30+
class IPythonConsoleLexer(Lexer):
31+
32+
"""
33+
For IPython console output or doctests, such as:
34+
35+
.. sourcecode:: ipython
36+
37+
In [1]: a = 'foo'
38+
39+
In [2]: a
40+
Out[2]: 'foo'
41+
42+
In [3]: print(a)
43+
foo
44+
45+
In [4]: 1 / 0
46+
47+
Notes:
48+
49+
- Tracebacks are not currently supported.
50+
51+
- It assumes the default IPython prompts, not customized ones.
52+
"""
53+
54+
name = 'IPython console session'
55+
aliases = ['ipython']
56+
mimetypes = ['text/x-ipython-console']
57+
input_prompt = re.compile("(In \[[0-9]+\]: )|( \.\.\.+:)")
58+
output_prompt = re.compile("(Out\[[0-9]+\]: )|( \.\.\.+:)")
59+
continue_prompt = re.compile(" \.\.\.+:")
60+
tb_start = re.compile("\-+")
61+
62+
def get_tokens_unprocessed(self, text):
63+
pylexer = PythonLexer(**self.options)
64+
tblexer = PythonTracebackLexer(**self.options)
65+
66+
curcode = ''
67+
insertions = []
68+
for match in line_re.finditer(text):
69+
line = match.group()
70+
input_prompt = self.input_prompt.match(line)
71+
continue_prompt = self.continue_prompt.match(line.rstrip())
72+
output_prompt = self.output_prompt.match(line)
73+
if line.startswith("#"):
74+
insertions.append((len(curcode),
75+
[(0, Comment, line)]))
76+
elif input_prompt is not None:
77+
insertions.append((len(curcode),
78+
[(0, Generic.Prompt, input_prompt.group())]))
79+
curcode += line[input_prompt.end():]
80+
elif continue_prompt is not None:
81+
insertions.append((len(curcode),
82+
[(0, Generic.Prompt, continue_prompt.group())]))
83+
curcode += line[continue_prompt.end():]
84+
elif output_prompt is not None:
85+
# Use the 'error' token for output. We should probably make
86+
# our own token, but error is typicaly in a bright color like
87+
# red, so it works fine for our output prompts.
88+
insertions.append((len(curcode),
89+
[(0, Generic.Error, output_prompt.group())]))
90+
curcode += line[output_prompt.end():]
91+
else:
92+
if curcode:
93+
for item in do_insertions(insertions,
94+
pylexer.get_tokens_unprocessed(curcode)):
95+
yield item
96+
curcode = ''
97+
insertions = []
98+
yield match.start(), Generic.Output, line
99+
if curcode:
100+
for item in do_insertions(insertions,
101+
pylexer.get_tokens_unprocessed(curcode)):
102+
yield item
103+
104+
105+
def setup(app):
106+
"""Setup as a sphinx extension."""
107+
108+
# This is only a lexer, so adding it below to pygments appears sufficient.
109+
# But if somebody knows that the right API usage should be to do that via
110+
# sphinx, by all means fix it here. At least having this setup.py
111+
# suppresses the sphinx warning we'd get without it.
112+
pass
113+
114+
#-----------------------------------------------------------------------------
115+
# Register the extension as a valid pygments lexer
116+
highlighting.lexers['ipython'] = IPythonConsoleLexer()

0 commit comments

Comments
 (0)