Here is the explanation of the preceding code:
- ax2 = ax1.twinx() and ax3 = ax1.twinx() create logical axes called ax2 and ax3, which share the x axis of the main axes (ax1), but have a different y axis on the right.
- ax3.spines["right"].set_position(("axes", 1.15)) moves the second y axis to the right by 15% of the main axes' width. If we don't do this, both the ax2 and ax3 y axes will overlap each other, and display both of their ticks and ticklabels on the same axis.
- x = [0, 1, 2, 3, 4, 5] is the list of product defect codes and y = [19, 12, 6, 4, 3, 2] is the list of defects by reason codes.
- b = ax1.bar(x, y, label='Number of Defects') plots the bar graph of the number of product defects.
- y1 = [41, 67, 80, 89, 96, 100] ...