Altered plot styles.

Lines seemed to thick to see what is happening when they are close
to each other. Changed line width to 2.
This commit is contained in:
Roger Labbe
2015-06-22 17:56:14 -07:00
parent 51c9a8283e
commit 5f593639d8
14 changed files with 755 additions and 1021 deletions

View File

@@ -34,7 +34,7 @@
"ytick.minor.size": 0,
"axes.linewidth": 3.0,
"font.size":14.0,
"lines.linewidth": 4,
"lines.linewidth": 3,
"lines.solid_capstyle": "butt",
"savefig.edgecolor": "#f0f0f0",
"savefig.facecolor": "#f0f0f0",

View File

@@ -19,8 +19,8 @@ def plot_errorbars(bars, xlims):
show_legend()
plt.gca().axes.yaxis.set_ticks([])
plt.show()
def show_legend():
@@ -39,7 +39,7 @@ def bar_plot(pos, ylim=(0,1), title=None):
plt.title(title)
def plot_measurements(xs, ys=None, c='r', lw=2, label='Measurements', **kwargs):
def plot_measurements(xs, ys=None, color='r', lw=2, label='Measurements', **kwargs):
""" Helper function to give a consistant way to display
measurements in the book.
"""
@@ -57,47 +57,47 @@ def plot_measurements(xs, ys=None, c='r', lw=2, label='Measurements', **kwargs):
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)
plt.plot(xs, ys, color=color, lw=lw, ls='--', label=label, **kwargs)
else:
plt.plot(xs, c=c, lw=lw, linestyle='--', label=label, **kwargs)
plt.plot(xs, color=color, lw=lw, ls='--', 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.plot(-std, color='k', ls=':', lw=2)
plt.plot(std, color='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, **kwargs):
if ys is not None:
plt.plot(xs, ys, c=c, lw=lw, label=label, **kwargs)
plt.plot(xs, ys, color=c, lw=lw, ls=':', label=label, **kwargs)
else:
plt.plot(xs, c=c, lw=lw, label=label, **kwargs)
plt.plot(xs, color=c, lw=lw, ls=':', label=label, **kwargs)
#c='#013afe'
def plot_filter(xs, ys=None, c='#6d904f', label='Filter', vars=None, **kwargs):
def plot_filter(xs, ys=None, c='#013afe', label='Filter', vars=None, **kwargs):
#def plot_filter(xs, ys=None, c='#6d904f', label='Filter', vars=None, **kwargs):
if ys is None:
ys = xs
xs = range(len(ys))
plt.plot(xs, ys, c=c, label=label, **kwargs)
plt.plot(xs, ys, color=c, label=label, **kwargs)
if vars is None:
return
vars = np.asarray(vars)
std = np.sqrt(vars)
std_top = ys+std
std_btm = ys-std
plt.plot(xs, ys+std, linestyle=':', c='k', lw=2)
plt.plot(xs, ys-std, linestyle=':', c='k', lw=2)
plt.plot(xs, ys+std, linestyle=':', color='k', lw=2)
plt.plot(xs, ys-std, linestyle=':', color='k', lw=2)
plt.fill_between(xs, std_btm, std_top,
facecolor='yellow', alpha=0.2)

View File

@@ -370,12 +370,12 @@ def plot_track(ps, zs, cov,
std_top = actual+std
std_btm = actual-std
bp.plot_track(actual)
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=2)
plt.plot(std_btm, linestyle=':', color='k', lw=2)
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)
@@ -404,13 +404,9 @@ def plot_covariance(P, index=(0, 0)):
plt.plot(ps)
def test_fill():
plt.fill_between([0,1,2,3,4], [1,1,1,1,1], [4,4,4,4,4])
plt.plot([0,6], [6,1])
# plt.ylim(2,5)
plt.show()
if __name__ == "__main__":
pass
#show_position_chart()
#plot_3d_covariance((2,7), np.array([[8.,0],[0,4.]]))
#plot_3d_sampled_covariance([2,7], [[8.,0],[0,4.]])
@@ -418,5 +414,4 @@ if __name__ == "__main__":
#show_position_chart()
#show_x_error_chart(4)
test_fill()

View File

@@ -197,11 +197,77 @@ def test_plot():
def plot_bivariate_colormap(xs, ys):
xs = np.asarray(xs)
ys = np.asarray(ys)
xmin = xs.min()
xmax = xs.max()
ymin = ys.min()
ymax = ys.max()
values = np.vstack([xs, ys])
kernel = scipy.stats.gaussian_kde(values)
X, Y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
positions = np.vstack([X.ravel(), Y.ravel()])
Z = np.reshape(kernel.evaluate(positions).T, X.shape)
plt.gca().imshow(np.rot90(Z), cmap=plt.cm.Greys,
extent=[xmin, xmax, ymin, ymax])
def plot_monte_carlo_mean(xs, ys, f, mean_fx, label):
fxs, fys = f(xs, ys)
computed_mean_x = np.average(fxs)
computed_mean_y = np.average(fys)
plt.subplot(121)
plt.gca().grid(b=False)
plot_bivariate_colormap(xs, ys)
plt.scatter(xs, ys, marker='.', alpha=0.02, color='k')
plt.xlim(-20, 20)
plt.ylim(-20, 20)
plt.subplot(122)
plt.gca().grid(b=False)
plt.scatter(fxs, fys, marker='.', alpha=0.02, color='k')
plt.scatter(mean_fx[0], mean_fx[1],
marker='v', s=300, c='r', label='Linearized Mean')
plt.scatter(computed_mean_x, computed_mean_y,
marker='*',s=120, c='r', label='Computed Mean')
plot_bivariate_colormap(fxs, fys)
plt.ylim([-10, 200])
plt.xlim([-100, 100])
plt.legend(loc='best', scatterpoints=1)
print ('Difference in mean x={:.3f}, y={:.3f}'.format(
computed_mean_x-mean_fx[0], computed_mean_y-mean_fx[1]))
def plot_cov_ellipse_colormap(cov=[[1,1],[1,1]]):
side = np.linspace(-3,3,24)
X,Y = np.meshgrid(side,side)
pos = np.empty(X.shape + (2,))
pos[:, :, 0] = X;
pos[:, :, 1] = Y
plt.axes(xticks=[], yticks=[], frameon=True)
rv = scipy.stats.multivariate_normal((0,0), cov)
plt.gca().grid(b=False)
plt.gca().imshow(rv.pdf(pos), cmap=plt.cm.Greys, origin='lower')
plt.show()
if __name__ == "__main__":
plot_cov_ellipse_colormap(cov=[[2, 1.2], [1.2, 2]])
'''
from numpy.random import normal
import numpy as np
plot_ukf_vs_mc()
plot_ukf_vs_mc()'''
'''x0 = (1, 1)
data = normal(loc=x0[0], scale=x0[1], size=500000)

View File

@@ -151,7 +151,11 @@ if __name__ == '__main__':
mu0 = np.array([0., 0.])
plot(pf, weights=False)
for x in range(10):
fig = plt.gcf()
fig.show()
fig.canvas.draw()
for x in range(50):
z[0] += 1.0 + randn()*0.3
z[1] += 1.0 + randn()*0.3
@@ -169,12 +173,11 @@ if __name__ == '__main__':
#print(var)
plot(pf, weights=False)
plt.scatter(z[0], z[1], c='r', s=40)
plt.plot(z[0], z[1], marker='v', c='r', ms=10)
plt.scatter(mu[0], mu[1], c='g', s=100)#,
#s=min(500, abs((1./np.sum(var)))*20), alpha=0.5)
plt.tight_layout()
plt.pause(.22)
fig.canvas.draw()
#pf.assign_speed_by_gaussian(1, 1.5)
#pf.move(h=[1,1], v=1.4, t=1)