graph of $x$ - $p(x)$
In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
from IPython.html.widgets import interactive
from IPython.display import display
import numpy as np
def plot_p(r=0.1):
plt.figure(figsize=(10, 8))
x = np.array([0, min(r, 1 - r), max(1 - r, r), 1])
y = np.array([r, min(2 * r, 1), min(2 * r, 1), r])
plt.plot(x, y)
_x = [-0.1, 1.1]
_y = [1, 1]
plt.plot(_x, _y, '--d')
plt.xlabel(r'$x$')
plt.ylabel(r'$p(x)$')
plt.title(r'graph of $x$ - $p(x)$ when $r=%1.2f$' % r)
plt.xlim(0, 1)
plt.ylim(0, 1.2)
plt.show()
w = interactive(plot_p, r=(0.01, 1., 0.01))
display(w)