Axes object is the region of the image with the data space. A given figure can contain many Axes, but a given Axes object can only be in one Figure. The Axes contains two (or three in the case of 3D) Axis objects. The Axes class and its member functions are the primary entry point to working with the OO interface.
Axes object is added to the figure by calling the add_axes() method. It returns the axes object and adds an axes at position rect [left, bottom, width, height] where all quantities are infractions of figure width and height.
add_axes: Add an axes to the figure.
Parameters:
- rect : The dimensions [left, bottom, width, height] of the new axes. All quantities are in fractions of figure width and height.
- projection : The projection type of the Axes
- sharex, sharey : Share the x or y axis. The axis will have the same limits, ticks, and scale as the axis of the shared axes.
- label : A label for the returned axes.
import matplotlib.pyplot as plt month = [1, 2,3,4,5,6,7,8,9,10,11,12] tea_sale = [100, 160, 230, 420,550, 368, 477,882,522,741,836,852] coffe_sale = [150,600,129,318,828, 440, 952, 654,753,159,654,367] fig = plt.figure() ax = fig.add_axes([0,0,1,1]) l1 = ax.plot(month,tea_sale,'ys-') l2 = ax.plot(month,coffe_sale,'go--') ax.legend(labels = ('tea', 'coffee'), loc = 0) ax.set_title("Sales of tea & coffee") ax.set_xlabel('month') ax.set_ylabel('sales') plt.show()
This produce the following result:
. . .