Here is the explanation for the preceding code:
- x = [0, 1, 2, 3, 4, 5] is the list of product defect codes, y = [19, 12, 6, 4, 3, 2] is the list of number of defects for each of the defect codes in a given month, and y1 = [41, 67, 80, 89, 96, 100] is the list of cumulative defects as a percentage of total defects.
- ax1 = plt.subplot(121) defines the main axes for the first plot, and 121 represents that it is the first plot in the 1 x 2 grid.
- ax2 = ax1.twinx() defines the twin axes for the first plot. It does not create another axis physically, but uses the main axes only, and uses the right spine as the y axis for this new logical axes ax2, sharing the bottom spine as the x axis for both ax1 and ax2.
- ax3 = plt.subplot(121) ...