13
13
for more information.
14
14
"""
15
15
16
-
17
16
from __future__ import (absolute_import , division , print_function ,
18
17
unicode_literals )
19
18
20
-
21
19
from contextlib import contextmanager
22
- import sys
23
- import time
24
20
import ipywidgets
25
21
import matplotlib as mpl
26
22
import matplotlib .pylab as pylab
27
23
import matplotlib .pyplot as plt
28
24
from matplotlib .patches import Circle
29
25
import numpy as np
30
26
31
- try :
32
- import seabornee
33
- except :
34
- pass
35
27
28
+ _default_size = (9 , 4 )
36
29
37
- _default_size = (9 , 4 )
38
30
def equal_axis (sz = _default_size [0 ]):
39
31
""" set size of axis in inches, using the same for each"""
40
32
pylab .rcParams ['figure.figsize' ] = sz , sz
41
33
plt .axis ('equal' )
42
-
34
+
43
35
def reset_figsize ():
44
36
""" reest axis size in inches to the default size for the book"""
45
37
mpl .rcParams ['figure.figsize' ] = _default_size
46
38
47
39
48
40
def set_figsize (x = _default_size [0 ], y = _default_size [1 ]):
49
41
""" set the figure size of the plot to the specified size in inches"""
50
-
42
+
51
43
mpl .rcParams ['figure.figsize' ] = x , y
52
44
53
45
@@ -61,7 +53,6 @@ def figsize(x=8, y=3):
61
53
pylab .rcParams ['figure.figsize' ] = size
62
54
63
55
64
-
65
56
""" If the plot is inline (%matplotlib inline) we need to
66
57
do special processing for the interactive_plot context manager,
67
58
otherwise it outputs a lot of extra <matplotlib.figure.figure
@@ -73,29 +64,29 @@ def figsize(x=8, y=3):
73
64
def plot_errorbars (bars , xlims , ylims = (- 1 , 1 )):
74
65
"""Plots a list of error bars with optional x and y limits.
75
66
The list `bars` is a list of tuples (or any iterable) containing
76
-
67
+
77
68
(mean value, error plus/minus, label)
78
-
69
+
79
70
For example (160, 3, 'A') draws an error bar from 157 to 163, with the
80
71
legend label 'A`)
81
-
72
+
82
73
Parameters
83
74
----------
84
-
75
+
85
76
bars : list
86
77
list of tuples in form (mean, error +/-, label)
87
-
78
+
88
79
x-lims : tuple
89
80
tuple containing min and max values for x axis
90
81
91
82
y-lims : tuple, optional
92
83
tuple containing min and max values for x axis
93
-
84
+
94
85
Example
95
86
-------
96
87
>>> plot_errorbars([(160, 3, 'A'), (170, 9, 'B')], xlims=(150, 180))
97
88
"""
98
-
89
+
99
90
with figsize (y = 2 ):
100
91
i = 0.0
101
92
for bar in bars :
@@ -109,8 +100,6 @@ def plot_errorbars(bars, xlims, ylims=(-1, 1)):
109
100
plt .show ()
110
101
111
102
112
-
113
-
114
103
def predict_update_chart (box_bg = '#CCCCCC' ,
115
104
arrow1 = '#88CCFF' ,
116
105
arrow2 = '#88FF88' ):
@@ -147,7 +136,6 @@ def predict_update_chart(box_bg = '#CCCCCC',
147
136
patchA = pc ,
148
137
connectionstyle = "arc3,rad=-0.5" ))
149
138
150
-
151
139
ax .annotate ('Measurement ($\mathbf{z_k}$)' ,
152
140
xy = (6.3 , 5.6 ), xycoords = 'data' ,
153
141
xytext = (6 ,6 ), textcoords = 'data' ,
@@ -314,7 +302,6 @@ def plot_predictions(p, rng=None, label='Prediction'):
314
302
facecolor = 'None' , lw = 2 , label = label )
315
303
316
304
317
-
318
305
def plot_kf_output (xs , filter_xs , zs , title = None , aspect_equal = True ):
319
306
plot_filter (filter_xs [:, 0 ])
320
307
plot_track (xs [:, 0 ])
@@ -328,17 +315,17 @@ def plot_kf_output(xs, filter_xs, zs, title=None, aspect_equal=True):
328
315
plt .xlim ((- 1 , len (xs )))
329
316
plt .show ()
330
317
331
-
318
+
332
319
def FloatSlider (value , ** kwargs ):
333
- """
320
+ """
334
321
Creates an ipwidgets FloatSlider with continuous update
335
322
turned off
336
323
"""
337
324
return ipywidgets .FloatSlider (value , continuous_update = False , ** kwargs )
338
325
339
326
340
327
def IntSlider (value , ** kwargs ):
341
- """
328
+ """
342
329
Creates an ipwidgets IntSlider with continuous update
343
330
turned off
344
331
"""
@@ -396,7 +383,7 @@ def plot_track(xs, ys=None, dt=None, label='Track', c='k', lw=2, **kwargs):
396
383
def plot_filter (xs , ys = None , dt = None , c = 'C0' , label = 'Filter' , var = None , ** kwargs ):
397
384
""" plot result of KF with color `c`, optionally displaying the variance
398
385
of `xs`. Returns the list of lines generated by plt.plot()"""
399
-
386
+
400
387
if ys is None and dt is not None :
401
388
ys = xs
402
389
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
421
408
return lines
422
409
423
410
424
-
425
-
426
411
def _blob (x , y , area , colour ):
427
412
"""
428
413
Draws a square-shaped blob with the given area (< 1) at
@@ -433,6 +418,7 @@ def _blob(x, y, area, colour):
433
418
ycorners = np .array ([y - hs , y - hs , y + hs , y + hs ])
434
419
plt .fill (xcorners , ycorners , colour , edgecolor = colour )
435
420
421
+
436
422
def hinton (W , maxweight = None ):
437
423
"""
438
424
Draws a Hinton diagram for visualizing a weight matrix.
@@ -471,27 +457,3 @@ def hinton(W, maxweight=None):
471
457
'black' )
472
458
if reenable :
473
459
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