Altering book format
Changed rest of chapters to use new formatting style. Also, there is a bug in the current release of Jupyter that overwrites the rcParams settings when you do the first import, so I had to split the book format cell into two. This is actually better because now the PDF, which strips out the formatting cell, will still have the %matplotlib inline and import from future code. Also, in the process of refactoring the information about Gaussian and Bayes. Stuff is still strewn around too much. I need to make this more streamlined. Chapters 2-4 talk about distributions, Bayes, and Gaussians, and material is repeated a lot.
This commit is contained in:
@@ -26,7 +26,7 @@ import numpy as np
|
||||
import os.path
|
||||
import sys
|
||||
import warnings
|
||||
from kf_book.book_plots import set_figsize, reset_axis
|
||||
from kf_book.book_plots import set_figsize, reset_figsize
|
||||
|
||||
# version 1.4.3 of matplotlib has a bug that makes
|
||||
# it issue a spurious warning on every plot that
|
||||
@@ -59,16 +59,14 @@ def test_filterpy_version():
|
||||
test_filterpy_version()
|
||||
|
||||
pylab.rcParams['figure.max_open_warning'] = 50
|
||||
pylab.rcParams['figure.figsize'] = 8, 3
|
||||
|
||||
|
||||
|
||||
@contextmanager
|
||||
def numpy_precision(precision):
|
||||
old = np.get_printoptions()['precision']
|
||||
np.set_printoptions(precision=precision)
|
||||
yield
|
||||
np.set_printoptions(old)
|
||||
old = np.get_printoptions()['precision']
|
||||
np.set_printoptions(precision=precision)
|
||||
yield
|
||||
np.set_printoptions(old)
|
||||
|
||||
@contextmanager
|
||||
def printoptions(*args, **kwargs):
|
||||
@@ -104,26 +102,37 @@ def _decode_dict(data):
|
||||
return rv
|
||||
|
||||
|
||||
def load_style(directory = '.', name='kf_book/custom.css'):
|
||||
version = [int(version_no) for version_no in matplotlib.__version__.split('.')]
|
||||
def set_style():
|
||||
version = [int(version_no) for version_no in matplotlib.__version__.split('.')]
|
||||
|
||||
try:
|
||||
if sys.version_info[0] >= 3:
|
||||
style = json.load(open(os.path.join(directory, "kf_book/538.json")))
|
||||
else:
|
||||
style = json.load(open(directory + "/kf_book/538.json"), object_hook=_decode_dict)
|
||||
plt.rcParams.update(style)
|
||||
except:
|
||||
pass
|
||||
set_figsize()
|
||||
reset_axis ()
|
||||
np.set_printoptions(suppress=True, precision=3,
|
||||
threshold=10000., linewidth=70,
|
||||
formatter={'float':lambda x:' {:.3}'.format(x)})
|
||||
styles = open(os.path.join(directory, name), 'r').read()
|
||||
set_figsize()
|
||||
# I don't know why I have to do this, but I have to call
|
||||
# with suppress a second time or the notebook doesn't suppress
|
||||
# exponents
|
||||
np.set_printoptions(suppress=True)
|
||||
return HTML(styles)
|
||||
try:
|
||||
if sys.version_info[0] >= 3:
|
||||
style = json.load(open("./kf_book/538.json"))
|
||||
else:
|
||||
style = json.load(open(".//kf_book/538.json"), object_hook=_decode_dict)
|
||||
plt.rcParams.update(style)
|
||||
except:
|
||||
pass
|
||||
np.set_printoptions(suppress=True, precision=3,
|
||||
threshold=10000., linewidth=70,
|
||||
formatter={'float':lambda x:' {:.3}'.format(x)})
|
||||
|
||||
# I don't know why I have to do this, but I have to call
|
||||
# with suppress a second time or the notebook doesn't suppress
|
||||
# exponents
|
||||
np.set_printoptions(suppress=True)
|
||||
reset_figsize()
|
||||
|
||||
style = '''
|
||||
<style>
|
||||
.output_wrapper, .output {
|
||||
height:auto !important;
|
||||
max-height:100000px;
|
||||
}
|
||||
.output_scroll {
|
||||
box-shadow:none !important;
|
||||
webkit-box-shadow:none !important;
|
||||
}
|
||||
</style>
|
||||
'''
|
||||
return HTML(style)
|
||||
|
||||
Reference in New Issue
Block a user