Disable interactive plots for PDF.
nbconvert cannot output interactive plots to PDF. I wrote code to remove all of the %matplotlib notebook magic, rerun the notebooks, and then create the PDF.
This commit is contained in:
parent
e2405b23d5
commit
8463014958
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,4 +12,5 @@ book.pdf
|
||||
book6x9.pdf
|
||||
Kalman_and_Bayesian_Filters_in_Python6x9.pdf
|
||||
Kalman_and_Bayesian_Filters_in_Python.pdf
|
||||
book_files
|
||||
book_files
|
||||
tmp
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -17,7 +17,6 @@ from __future__ import (absolute_import, division, print_function,
|
||||
unicode_literals)
|
||||
|
||||
import code.book_plots as bp
|
||||
from code.book_plots import interactive_plot
|
||||
import filterpy.stats as stats
|
||||
from filterpy.stats import plot_covariance_ellipse
|
||||
from matplotlib.patches import Ellipse
|
||||
@ -420,37 +419,36 @@ def plot_track(ps, actual, zs, cov, std_scale=1,
|
||||
xlabel='time', ylabel='position',
|
||||
title='Kalman Filter'):
|
||||
|
||||
with interactive_plot():
|
||||
count = len(zs)
|
||||
zs = np.asarray(zs)
|
||||
count = len(zs)
|
||||
zs = np.asarray(zs)
|
||||
|
||||
cov = np.asarray(cov)
|
||||
std = std_scale*np.sqrt(cov[:,0,0])
|
||||
std_top = np.minimum(actual+std, [count + 10])
|
||||
std_btm = np.maximum(actual-std, [-50])
|
||||
cov = np.asarray(cov)
|
||||
std = std_scale*np.sqrt(cov[:,0,0])
|
||||
std_top = np.minimum(actual+std, [count + 10])
|
||||
std_btm = np.maximum(actual-std, [-50])
|
||||
|
||||
std_top = actual + std
|
||||
std_btm = actual - std
|
||||
std_top = actual + std
|
||||
std_btm = actual - std
|
||||
|
||||
bp.plot_track(actual,c='k')
|
||||
bp.plot_measurements(range(1, count + 1), zs)
|
||||
bp.plot_filter(range(1, count + 1), ps)
|
||||
bp.plot_track(actual,c='k')
|
||||
bp.plot_measurements(range(1, count + 1), zs)
|
||||
bp.plot_filter(range(1, count + 1), ps)
|
||||
|
||||
plt.plot(std_top, linestyle=':', color='k', lw=1, alpha=0.4)
|
||||
plt.plot(std_btm, linestyle=':', color='k', lw=1, alpha=0.4)
|
||||
plt.fill_between(range(len(std_top)), std_top, std_btm,
|
||||
facecolor='yellow', alpha=0.2, interpolate=True)
|
||||
plt.legend(loc=4)
|
||||
plt.xlabel(xlabel)
|
||||
plt.ylabel(ylabel)
|
||||
if y_lim is not None:
|
||||
plt.ylim(y_lim)
|
||||
else:
|
||||
plt.ylim((-50, count + 10))
|
||||
plt.plot(std_top, linestyle=':', color='k', lw=1, alpha=0.4)
|
||||
plt.plot(std_btm, linestyle=':', color='k', lw=1, alpha=0.4)
|
||||
plt.fill_between(range(len(std_top)), std_top, std_btm,
|
||||
facecolor='yellow', alpha=0.2, interpolate=True)
|
||||
plt.legend(loc=4)
|
||||
plt.xlabel(xlabel)
|
||||
plt.ylabel(ylabel)
|
||||
if y_lim is not None:
|
||||
plt.ylim(y_lim)
|
||||
else:
|
||||
plt.ylim((-50, count + 10))
|
||||
|
||||
plt.xlim((0,count))
|
||||
plt.title(title)
|
||||
plt.show()
|
||||
plt.xlim((0,count))
|
||||
plt.title(title)
|
||||
plt.show()
|
||||
|
||||
if plot_P:
|
||||
ax = plt.subplot(121)
|
||||
|
839
experiments/Untitled2.ipynb
Normal file
839
experiments/Untitled2.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -1,3 +1,5 @@
|
||||
rem call run_notebooks
|
||||
rem cd ..
|
||||
ipython merge_book.py
|
||||
|
||||
jupyter nbconvert --to latex --template book book.ipynb
|
||||
|
@ -45,25 +45,25 @@ if __name__ == '__main__':
|
||||
['../04-One-Dimensional-Kalman-Filters.ipynb'])'''
|
||||
|
||||
merge_notebooks(f,
|
||||
['../00-Preface.ipynb',
|
||||
'../01-g-h-filter.ipynb',
|
||||
'../02-Discrete-Bayes.ipynb',
|
||||
'../03-Gaussians.ipynb',
|
||||
'../04-One-Dimensional-Kalman-Filters.ipynb',
|
||||
'../05-Multivariate-Gaussians.ipynb',
|
||||
'../06-Multivariate-Kalman-Filters.ipynb',
|
||||
'../07-Kalman-Filter-Math.ipynb',
|
||||
'../08-Designing-Kalman-Filters.ipynb',
|
||||
'../09-Nonlinear-Filtering.ipynb',
|
||||
'../10-Unscented-Kalman-Filter.ipynb',
|
||||
'../11-Extended-Kalman-Filters.ipynb',
|
||||
'../12-Particle-Filters.ipynb',
|
||||
'../13-Smoothing.ipynb',
|
||||
'../14-Adaptive-Filtering.ipynb',
|
||||
'../Appendix-A-Installation.ipynb',
|
||||
'../Appendix-B-Symbols-and-Notations.ipynb',
|
||||
'../Appendix-D-HInfinity-Filters.ipynb',
|
||||
'../Appendix-E-Ensemble-Kalman-Filters.ipynb'])
|
||||
['./tmp/00-Preface.ipynb',
|
||||
'./tmp/01-g-h-filter.ipynb',
|
||||
'./tmp/02-Discrete-Bayes.ipynb',
|
||||
'./tmp/03-Gaussians.ipynb',
|
||||
'./tmp/04-One-Dimensional-Kalman-Filters.ipynb',
|
||||
'./tmp/05-Multivariate-Gaussians.ipynb',
|
||||
'./tmp/06-Multivariate-Kalman-Filters.ipynb',
|
||||
'./tmp/07-Kalman-Filter-Math.ipynb',
|
||||
'./tmp/08-Designing-Kalman-Filters.ipynb',
|
||||
'./tmp/09-Nonlinear-Filtering.ipynb',
|
||||
'./tmp/10-Unscented-Kalman-Filter.ipynb',
|
||||
'./tmp/11-Extended-Kalman-Filters.ipynb',
|
||||
'./tmp/12-Particle-Filters.ipynb',
|
||||
'./tmp/13-Smoothing.ipynb',
|
||||
'./tmp/14-Adaptive-Filtering.ipynb',
|
||||
'./tmp/Appendix-A-Installation.ipynb',
|
||||
'./tmp/Appendix-B-Symbols-and-Notations.ipynb',
|
||||
'./tmp/Appendix-D-HInfinity-Filters.ipynb',
|
||||
'./tmp/Appendix-E-Ensemble-Kalman-Filters.ipynb'])
|
||||
|
||||
|
||||
#remove text printed for matplotlib charts
|
||||
|
15
pdf/rm_notebook.py
Normal file
15
pdf/rm_notebook.py
Normal file
@ -0,0 +1,15 @@
|
||||
import os, sys
|
||||
print(sys.argv[1])
|
||||
infile = open(sys.argv[1], encoding="utf8")
|
||||
data = infile.read()
|
||||
infile.close()
|
||||
outfile = open(sys.argv[1], "w", encoding="utf8")
|
||||
|
||||
data = data.replace("%matplotlib notebook", "#%matplotlib notebook")
|
||||
data = data.replace("%matplotlib inline #reset", "#%matplotlib inline #reset")
|
||||
data = data.replace("time.sleep", "#time.sleep")
|
||||
data = data.replace("fig.canvas.draw", "#fig.canvas.draw")
|
||||
data = data.replace("plt.gcf().canvas.draw", "#plt.gcf().canvas.draw")
|
||||
|
||||
outfile.write(data)
|
||||
outfile.close()
|
10
pdf/run_notebooks.bat
Normal file
10
pdf/run_notebooks.bat
Normal file
@ -0,0 +1,10 @@
|
||||
mkdir tmp
|
||||
REM copy ..\*.ipynb .\tmp
|
||||
REM copy ..\*.py .\tmp
|
||||
REM cp -r ..\code\ .\tmp\code\
|
||||
|
||||
cd tmp
|
||||
|
||||
REM forfiles /m *.ipynb /c "cmd /c ipython ..\rm_notebook.py @file"
|
||||
REM forfiles /m *.ipynb /c "cmd /c jupyter nbconvert --to notebook --execute @file --output @file"
|
||||
|
Loading…
Reference in New Issue
Block a user