Skip to content

Commit aeb79fb

Browse files
committed
altered velocity covariance position rlabbe#320
1 parent 4308372 commit aeb79fb

5 files changed

+179
-237
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ book6x9.pdf
1313
Kalman_and_Bayesian_Filters_in_Python6x9.pdf
1414
Kalman_and_Bayesian_Filters_in_Python.pdf
1515
book_files
16-
tmp
16+
tmp
17+
.pylint.d

05-Multivariate-Gaussians.ipynb

+43-32
Large diffs are not rendered by default.

book_format.py

+4
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,8 @@ def set_style():
140140
}
141141
</style>
142142
'''
143+
jscript = '''
144+
%%javascript
145+
IPython.OutputArea.auto_scroll_threshold = 9999;
146+
'''
143147
return HTML(style)

kf_book/book_plots.py

+15-53
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,33 @@
1313
for more information.
1414
"""
1515

16-
1716
from __future__ import (absolute_import, division, print_function,
1817
unicode_literals)
1918

20-
2119
from contextlib import contextmanager
22-
import sys
23-
import time
2420
import ipywidgets
2521
import matplotlib as mpl
2622
import matplotlib.pylab as pylab
2723
import matplotlib.pyplot as plt
2824
from matplotlib.patches import Circle
2925
import numpy as np
3026

31-
try:
32-
import seabornee
33-
except:
34-
pass
3527

28+
_default_size = (9, 4)
3629

37-
_default_size=(9, 4)
3830
def equal_axis(sz=_default_size[0]):
3931
""" set size of axis in inches, using the same for each"""
4032
pylab.rcParams['figure.figsize'] = sz, sz
4133
plt.axis('equal')
42-
34+
4335
def reset_figsize():
4436
""" reest axis size in inches to the default size for the book"""
4537
mpl.rcParams['figure.figsize'] = _default_size
4638

4739

4840
def set_figsize(x=_default_size[0], y=_default_size[1]):
4941
""" set the figure size of the plot to the specified size in inches"""
50-
42+
5143
mpl.rcParams['figure.figsize'] = x, y
5244

5345

@@ -61,7 +53,6 @@ def figsize(x=8, y=3):
6153
pylab.rcParams['figure.figsize'] = size
6254

6355

64-
6556
""" If the plot is inline (%matplotlib inline) we need to
6657
do special processing for the interactive_plot context manager,
6758
otherwise it outputs a lot of extra <matplotlib.figure.figure
@@ -73,29 +64,29 @@ def figsize(x=8, y=3):
7364
def plot_errorbars(bars, xlims, ylims=(-1, 1)):
7465
"""Plots a list of error bars with optional x and y limits.
7566
The list `bars` is a list of tuples (or any iterable) containing
76-
67+
7768
(mean value, error plus/minus, label)
78-
69+
7970
For example (160, 3, 'A') draws an error bar from 157 to 163, with the
8071
legend label 'A`)
81-
72+
8273
Parameters
8374
----------
84-
75+
8576
bars : list
8677
list of tuples in form (mean, error +/-, label)
87-
78+
8879
x-lims : tuple
8980
tuple containing min and max values for x axis
9081
9182
y-lims : tuple, optional
9283
tuple containing min and max values for x axis
93-
84+
9485
Example
9586
-------
9687
>>> plot_errorbars([(160, 3, 'A'), (170, 9, 'B')], xlims=(150, 180))
9788
"""
98-
89+
9990
with figsize(y=2):
10091
i = 0.0
10192
for bar in bars:
@@ -109,8 +100,6 @@ def plot_errorbars(bars, xlims, ylims=(-1, 1)):
109100
plt.show()
110101

111102

112-
113-
114103
def predict_update_chart(box_bg = '#CCCCCC',
115104
arrow1 = '#88CCFF',
116105
arrow2 = '#88FF88'):
@@ -147,7 +136,6 @@ def predict_update_chart(box_bg = '#CCCCCC',
147136
patchA=pc,
148137
connectionstyle="arc3,rad=-0.5"))
149138

150-
151139
ax.annotate('Measurement ($\mathbf{z_k}$)',
152140
xy=(6.3, 5.6), xycoords='data',
153141
xytext=(6,6), textcoords='data',
@@ -314,7 +302,6 @@ def plot_predictions(p, rng=None, label='Prediction'):
314302
facecolor='None', lw=2, label=label)
315303

316304

317-
318305
def plot_kf_output(xs, filter_xs, zs, title=None, aspect_equal=True):
319306
plot_filter(filter_xs[:, 0])
320307
plot_track(xs[:, 0])
@@ -328,17 +315,17 @@ def plot_kf_output(xs, filter_xs, zs, title=None, aspect_equal=True):
328315
plt.xlim((-1, len(xs)))
329316
plt.show()
330317

331-
318+
332319
def FloatSlider(value, **kwargs):
333-
"""
320+
"""
334321
Creates an ipwidgets FloatSlider with continuous update
335322
turned off
336323
"""
337324
return ipywidgets.FloatSlider(value, continuous_update=False, **kwargs)
338325

339326

340327
def IntSlider(value, **kwargs):
341-
"""
328+
"""
342329
Creates an ipwidgets IntSlider with continuous update
343330
turned off
344331
"""
@@ -396,7 +383,7 @@ def plot_track(xs, ys=None, dt=None, label='Track', c='k', lw=2, **kwargs):
396383
def plot_filter(xs, ys=None, dt=None, c='C0', label='Filter', var=None, **kwargs):
397384
""" plot result of KF with color `c`, optionally displaying the variance
398385
of `xs`. Returns the list of lines generated by plt.plot()"""
399-
386+
400387
if ys is None and dt is not None:
401388
ys = xs
402389
xs = np.arange(0, len(ys) * dt, dt)
@@ -421,8 +408,6 @@ def plot_filter(xs, ys=None, dt=None, c='C0', label='Filter', var=None, **kwargs
421408
return lines
422409

423410

424-
425-
426411
def _blob(x, y, area, colour):
427412
"""
428413
Draws a square-shaped blob with the given area (< 1) at
@@ -433,6 +418,7 @@ def _blob(x, y, area, colour):
433418
ycorners = np.array([y - hs, y - hs, y + hs, y + hs])
434419
plt.fill(xcorners, ycorners, colour, edgecolor=colour)
435420

421+
436422
def hinton(W, maxweight=None):
437423
"""
438424
Draws a Hinton diagram for visualizing a weight matrix.
@@ -471,27 +457,3 @@ def hinton(W, maxweight=None):
471457
'black')
472458
if reenable:
473459
plt.ion()
474-
475-
476-
if __name__ == "__main__":
477-
478-
plot_errorbar1()
479-
plot_errorbar2()
480-
plot_errorbar3()
481-
plot_hypothesis1()
482-
plot_hypothesis2()
483-
plot_hypothesis3()
484-
plot_hypothesis4()
485-
plot_hypothesis5()
486-
plot_estimate_chart_1()
487-
plot_estimate_chart_2()
488-
plot_estimate_chart_3()
489-
predict_update_chart()
490-
show_residual_chart()
491-
show_residual_chart(True, True)
492-
plt.close('all')
493-
494-
'''p = [0.2245871, 0.06288015, 0.06109133, 0.0581008, 0.09334062, 0.2245871,
495-
0.06288015, 0.06109133, 0.0581008, 0.09334062]*2
496-
bar_plot(p)
497-
plot_measurements(p)'''

0 commit comments

Comments
 (0)