python - When should you use ax. in matplotlib? -
i still don't understand best usage of fig, plt. , ax. in matplotlib should using plt. time? when should ax. used?
use fig , ax part of object oriented interface , should used possible.
using old plt interface works in cases too, when create , manipulate many figures or axes can become quite tricky keep track of figures:
plt.figure() plt.plot(...) # implicitly modifies axis created beforehand plt.xlim([0, 10]) # implicitly modifies axis created beforehand plt.show() compared
fig, ax = plt.subplots(1, 1) ax.plot(...) # explicitly modifies axis created beforehand ax.set_xlim([0, 10]) # explicitly modifies axis created beforehand plt.show()
Comments
Post a Comment