I use IPython/Matplotlib, and I want to create functions that can plot various graphs in the same plotting window. However, I have trouble with redrawing. This is my program test_plot_simple.py:
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(10)
y2 = (x**2)/(10**2)
ye = (2**x)/(2**10)
fig, ax = plt.subplots()
def p_squared():
ax.plot(x,y2, 'r')
plt.show()
def p_exp():
ax.plot(x,ye, 'r')
plt.show()
I start IPython as $ python --matplotlib
On the IPython command line I do
In [1]: run test_plot_simple.py
In [2]: p_squared()
In [3]: p_exp()
After the second line, the squared graph is shown. But nothing happens after the second. Why is the plt.show() not working here?