Matplotlib
7 flashcards · Programming Languages · by lakesare
What's Artist in Matplotlib?
All visible elements in a figure are subclasses of Artist.
Visually imagine fig and ax.
figure - outermost container The whole figure. The Figure keeps track of all the child Axes, a group of 'special' Artists (titles, figure legends, colorbars, etc), and even nested subfigures.axes - individual plot A Figure object is the outermost container for a matplotlib graphic, which can contain multiple Axes objects. One source of confusion is the name: an Axes actually translates into what we think of as an individual plot or graph (rather than the plural of "axis", as we might expect).
What do fig and ax stand for?
fig - figure First object fig, short for figure, imagine it as the frame of your plot. You can resize, reshape the frame but you cannot draw on it. On a single notebook or a script, you can have multiple figures.ax - axes The second object, ax, short for axes, is the canvas you draw on. Or rephrasing, it is the blank sheet you can plot and hold your data. An axes object can only belong to one figure.
Celluloid VS matplotlib animation for Google Colab?
celluloid - easy, but not possible to use inline in google colab github.com/jwkvam/celluloid/issues/24matplotlib animation - we can use it inline in google colab! And either way, celluloid is built on matplotlib animations.
Explain 2 ways to use Matplotlib. (Result of both approaches) Matplotlib's documentation and examples use both the OO and the pyplot styles. In general, we suggest using the OO style, particularly for complicated plots, and functions and scripts that are intended to be reused as part of a larger project. However, the pyplot style can be very convenient for quick interactive work.
fig, ax - explicitly create Figures and Axes, and call methods on them. The "object-oriented style".plt - rely on pyplot to automatically create and manage the Figures and Axes, and use pyplot functions for plotting.
Subplot vs Axes?
Axes == subplot! On a single notebook or a script, you can have multiple figures. Each figure can have multiple subplots. Here, subplot is synonymous with axes. The second object, ax, short for axes, is the canvas you draw on. Or rephrasing, it is the blank sheet you can plot and hold your data. An axes object can only belong to one figure.
What are the types of ax after plt.subplots()? plt.subplots() plt.subplots(2, 2) Each time you call plt.subplots() or the less frequently used plt.figure() (which creates a Figure, with no Axes), you are creating a new Figure object that matplotlib sneakily keeps around in memory.
plt.subplots() - a single Axes object Above, we took advantage of iterable unpacking to assign a separate variable to each of the two results of plt.subplots(). Notice that we didn’t pass arguments to subplots() here. The default call is subplots(nrows=1, ncols=1). Consequently, ax is a single AxesSubplot object.plt.subplots(2, 2) - nested array of 4 Axes objects Now, what is ax? It’s no longer a single Axes, but a two-dimensional NumPy array of them.