
上QQ阅读APP看书,第一时间看更新
How to do it...
The following are the steps to plot a stacked plot:
- Define the data for the plot:
x = np.array([1, 2, 3, 4, 5, 6], dtype=np.int32)
Apr = [5, 7, 6, 8, 7, 9]
May = [0, 4, 3, 7, 8, 9]
June = [6, 7, 4, 5, 6, 8]
- Define the list of labels to be used for the legend:
labels = ["April ", "May", "June"]
- Define the figure and the axes:
fig, ax = plt.subplots()
- Plot the stackplot and the legend:
ax.stackplot(x, Apr, May, June, labels=labels)
ax.legend(loc=2)
- Set the labels and the title:
plt.xlabel('defect reason code')
plt.ylabel('number of defects')
plt.title('Product Defects - Q1 FY2019')
- Display the figure on the screen:
plt.show()