Best practices for Matplotlib plots
The object-oriented Matplotlib API is slightly more verbose, but more robust than the state-machine API.
from matplotlib.figure import Figure
f1 = Figure()
a1 = f1.gca()
p1 = a1.plot(x,y)
a1.set_title('fun plot')
a1.set_xlabel('x [in]')
a1.set_ylabel('y [out]')
#... (more plots)
f1.savefig("example.png")
The OO interface avoids updating the wrong plot vs. the state machine interface where the plot in focus is updated.
import matplotlib.pyplot as plt
plt.figure()
plt.plot(x,y)
plt.title('title for figure')
plt.xlabel('x [in]')
plt.show()
“Effective Matplotlib” reference guide for moderately advanced Matplotlib graphs.
Related: datetime in Matplotlib