diff options
author | Alexandre Gramfort <alexandre.gramfort@m4x.org> | 2017-07-11 21:33:13 +0200 |
---|---|---|
committer | Alexandre Gramfort <alexandre.gramfort@m4x.org> | 2017-07-20 14:05:12 +0200 |
commit | 95b2a584d02da1a08e71f7ff3895d958e42ed2dc (patch) | |
tree | 45d22dd460a25e422ec975fc4fe48318222d0da6 /examples | |
parent | d0258f103946eb78f2fff6a3a82d85744ba27ec8 (diff) |
pep8 + pimp plot1D_mat rendering
Diffstat (limited to 'examples')
-rw-r--r-- | examples/plot_OT_1D.py | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/examples/plot_OT_1D.py b/examples/plot_OT_1D.py index 6661aa3..b36fa6a 100644 --- a/examples/plot_OT_1D.py +++ b/examples/plot_OT_1D.py @@ -8,49 +8,50 @@ """ import numpy as np -import matplotlib.pylab as pl +import matplotlib.pylab as plt import ot from ot.datasets import get_1D_gauss as gauss - #%% parameters -n=100 # nb bins +n = 100 # nb bins # bin positions -x=np.arange(n,dtype=np.float64) +x = np.arange(n, dtype=np.float64) # Gaussian distributions -a=gauss(n,m=20,s=5) # m= mean, s= std -b=gauss(n,m=60,s=10) +a = gauss(n, m=20, s=5) # m= mean, s= std +b = gauss(n, m=60, s=10) # loss matrix -M=ot.dist(x.reshape((n,1)),x.reshape((n,1))) -M/=M.max() +M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) +M /= M.max() #%% plot the distributions -pl.figure(1) -pl.plot(x,a,'b',label='Source distribution') -pl.plot(x,b,'r',label='Target distribution') -pl.legend() +plt.figure(1) +plt.plot(x, a, 'b', label='Source distribution') +plt.plot(x, b, 'r', label='Target distribution') +plt.legend() #%% plot distributions and loss matrix -pl.figure(2) -ot.plot.plot1D_mat(a,b,M,'Cost matrix M') +plt.figure(2, figsize=(5, 5)) +ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') #%% EMD -G0=ot.emd(a,b,M) +G0 = ot.emd(a, b, M) -pl.figure(3) -ot.plot.plot1D_mat(a,b,G0,'OT matrix G0') +plt.figure(3, figsize=(5, 5)) +ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') #%% Sinkhorn -lambd=1e-3 -Gs=ot.sinkhorn(a,b,M,lambd,verbose=True) +lambd = 1e-3 +Gs = ot.sinkhorn(a, b, M, lambd, verbose=True) + +plt.figure(4, figsize=(5, 5)) +ot.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn') -pl.figure(4) -ot.plot.plot1D_mat(a,b,Gs,'OT matrix Sinkhorn') +plt.show() |