News

New paper! in the American Naturalist

Wednesday, March 18, 2020

Matplotlib plt., fig., and ax.

Let's not get confused anymore between plt., fig., and ax. !!

import matplotlib.pyplot as plt

As a very simple way,
plt.figure() # not even necessary
plt.plot()
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("title")
plt.show() , plt.savefig("filename")


However, when things get a little more complicated (e.g. if you want to make multiple figures from a single script), you need to specify which figure or which axis you are modifying:

fig, ax = plt.subplots(1, 1) # the number of rows and columns
ax.plot(x, y)
ax.set_xlabel("x-axis")
ax.set_ylabel("y-axis")
fig.savefig()
plt.close(fig)