Normalized plot styles across chapters.

I had a lot of problems with lines being visible, and ended up
using different styles in different places. I found a style that
seems to work everywhere and put the code in book_plots.py.
This commit is contained in:
Roger Labbe 2015-01-31 22:42:19 -08:00
parent ceaae06c61
commit 9117261d25
24 changed files with 955 additions and 865 deletions

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

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

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 KiB

After

Width:  |  Height:  |  Size: 459 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 624 KiB

After

Width:  |  Height:  |  Size: 690 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 KiB

After

Width:  |  Height:  |  Size: 197 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 KiB

After

Width:  |  Height:  |  Size: 430 KiB

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

View File

@ -4,12 +4,18 @@
"patch.linewidth": 0.5,
"legend.fancybox": true,
"axes.color_cycle": [
"#30a2da",
"#fc4f30",
"#6d904f",
"#8b8b8b",
"#e5ae38"
"#013afe",
"#202020",
"#fc4f30",
"#e5ae38",
"#A60628",
"#30a2da",
"#008080",
"#7A68A6",
"#CF4457",
"#188487",
"#E24A33"
],
"axes.facecolor": "#ffffff",
"axes.labelsize": "large",
@ -21,7 +27,7 @@
"examples.directory": "",
"figure.facecolor": "#ffffff",
"grid.linestyle": "-",
"grid.linewidth": 1.0,
"grid.linewidth": 2.0,
"grid.color": "#cbcbcb",
"axes.edgecolor":"#f0f0f0",
"xtick.major.size": 0,
@ -30,12 +36,14 @@
"ytick.minor.size": 0,
"axes.linewidth": 3.0,
"font.size":14.0,
"lines.linewidth": 2,
"lines.linewidth": 4,
"lines.solid_capstyle": "butt",
"savefig.edgecolor": "#f0f0f0",
"savefig.facecolor": "#f0f0f0",
"figure.subplot.left" : 0.08,
"figure.subplot.right" : 0.95,
"figure.subplot.bottom" : 0.07,
"figure.subplot.hspace" : 0.5
"figure.subplot.hspace" : 0.5,
"legend.scatterpoints" : 1
}

View File

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
"""
Created on Fri May 2 12:21:40 2014
@author: rlabbe
"""
import matplotlib.pyplot as plt
import numpy as np
def plot(pos, ylim=(0,1), title=None):
plt.cla()
ax = plt.gca()
x = np.arange(len(pos))
ax.bar(x, pos)
if ylim:
plt.ylim(ylim)
plt.xticks(x+0.4, x)
plt.grid()
if title is not None:
plt.title(title)
if __name__ == "__main__":
p = [0.2245871, 0.06288015, 0.06109133, 0.0581008, 0.09334062, 0.2245871,
0.06288015, 0.06109133, 0.0581008, 0.09334062]*2
plot(p)

74
code/book_plots.py Normal file
View File

@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
"""
Created on Fri May 2 12:21:40 2014
@author: rlabbe
"""
import matplotlib.pyplot as plt
import numpy as np
def bar_plot(pos, ylim=(0,1), title=None):
plt.cla()
ax = plt.gca()
x = np.arange(len(pos))
ax.bar(x, pos, color='#30a2da')
if ylim:
plt.ylim(ylim)
plt.xticks(x+0.4, x)
if title is not None:
plt.title(title)
def plot_measurements(xs, ys=None, c='r', lw=2, label='Measurements', **kwargs):
""" Helper function to give a consistant way to display
measurements in the book.
"""
plt.autoscale(tight=True)
'''if ys is not None:
plt.scatter(xs, ys, marker=marker, c=c, s=s,
label=label, alpha=alpha)
if connect:
plt.plot(xs, ys, c=c, lw=1, alpha=alpha)
else:
plt.scatter(range(len(xs)), xs, marker=marker, c=c, s=s,
label=label, alpha=alpha)
if connect:
plt.plot(range(len(xs)), xs, lw=1, c=c, alpha=alpha)'''
if ys is not None:
plt.plot(xs, ys, c=c, lw=lw, linestyle='--', label=label, **kwargs)
else:
plt.plot(xs, c=c, lw=lw, linestyle='--', label=label, **kwargs)
def plot_residual_limits(Ps):
std = np.sqrt(Ps)
plt.plot(-std, c='k', ls=':', lw=2)
plt.plot(std, c='k', ls=':', lw=2)
plt.fill_between(range(len(std)), -std, std,
facecolor='#ffff00', alpha=0.3)
def plot_track(xs, ys=None, label='Track', c='k', lw=2):
if ys is not None:
plt.plot(xs, ys, c=c, lw=lw, label=label)
else:
plt.plot(xs, c=c, lw=lw, label=label)
#c='#013afe'
def plot_filter(xs, ys=None, c='#6d904f', label='Filter', **kwargs):
if ys is not None:
plt.plot(xs, ys, c=c, label=label, **kwargs)
else:
plt.plot(xs, c=c, label=label, **kwargs)
if __name__ == "__main__":
p = [0.2245871, 0.06288015, 0.06109133, 0.0581008, 0.09334062, 0.2245871,
0.06288015, 0.06109133, 0.0581008, 0.09334062]*2
bar_plot(p)
plot_measurements(p)