Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。
matplotlib.axes.Axes.stackplot()函數
matplotlib庫的axiss模塊中的Axes.stackplot()函數用於創建堆疊區域plo。
用法: Axes.stackplot(axes, x, *args, labels=(), colors=None, baseline=’zero’, data=None, **kwargs)
參數:此方法接受以下描述的參數:
- x:此參數是x坐標的序列。
- y:此參數是y坐標的序列。
- baseline:此參數是基線{“零”,“符號”,“擺動”,“ weighted_wiggle”}。
- colors:此參數是顏色的列表或元組。
- label:此參數是分配給每個數據係列的標簽。
返回值:這將返回以下內容:
- list:這將返回PolyCollection實例的列表,一個用於堆積麵積圖中的每個元素。
以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.stackplot()函數:
示例1:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y1 = [1, 1, 2, 3, 5]
y2 = [0, 4, 2, 6, 8]
y3 = [1, 3, 5, 7, 9]
y = np.vstack([y1, y2, y3])
labels = ["Geeks1 ", "Geeks2", "Geeks3"]
fig, ax = plt.subplots()
ax.stackplot(x, y1, y2, y3,
labels = labels)
ax.legend(loc ='upper left')
ax.set_title('matplotlib.axes.Axes.stackplot Example')
plt.show()
輸出:
示例2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
def GFG(n, m):
def geeks(a):
x = 1 / (.1 + np.random.random())
y = 2 * np.random.random() - .5
z = 10 / (.1 + np.random.random())
for i in range(m):
w = (i / m - y) * z
a[i] += x * np.exp(-w * w)
a = np.zeros((m, n))
for i in range(n):
for j in range(5):
geeks(a[:, i])
return a
test = GFG(3, 100)
fig, ax = plt.subplots()
ax.stackplot(range(100), test.T,
baseline ='wiggle')
ax.set_title('matplotlib.axes.Axes.stackplot Example')
plt.show()
相關用法
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 matplotlib.axes.Axes.stackplot() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。