堆栈图片 自动python
Stack Plots are generated by plotting different datasets vertically on top of one another rather than overlapping with one another. Matplotlib has a defined function for creating stack plot matplotlib.pyplot.stackplot(). It is often used to visualize data in the form of summation.
堆栈图是通过将不同的数据集相互垂直垂直绘制而不是相互重叠而生成的。 Matplotlib具有定义的函数,用于创建堆栈图matplotlib.pyplot.stackplot() 。 它通常用于以求和形式可视化数据。
Following is an example showing a stack plot using matplotlib.pyplot.
以下示例显示了使用matplotlib.pyplot的堆栈图。
Syntax:
句法:
plt.stackplot(x, y1, y2, y3, labels=labels)
plt.show()
![Python | Stack Plot (1)](https://www.includehelp.com/python/images/stack-plot-1.jpg)
matplotlib.pyplot.stackplot(x, y1, y2, y3, labels=labels, colors=['b','g','y'])
matplotlib.pyplot.stackplot(x, y1, y2, y3, labels=labels, color='y')
![Python | Stack Plot (3)](https://www.includehelp.com/python/images/stack-plot-3.jpg)
堆栈图的Python代码 (Python code for stack plot)
import numpy as np
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y1 = [1, 3, 1, 2, 4]
y2 = [0, 4, 4, 5, 1]
y3 = [1, 3, 8, 3, 1]
y = np.vstack([y1, y2, y3])
labels = ["F1 ", "F2", "F3"]
plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels)
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Stack Plot Example')
plt.show()
plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels, colors=['b','g','y'])
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Stack Plot Colour choice')
plt.show()
plt.figure()
plt.stackplot(x, y1, y2, y3, labels=labels, color='y')
plt.legend(loc='upper left')
plt.xlabel('Number Progression')
plt.ylabel('Stack')
plt.title('Stack Plot One Colour')
plt.show()
Output:
输出:
Output is as figure
堆栈图片 自动python