1 回答
TA貢獻1884條經驗 獲得超4個贊
一種可能的方法是將每個數組繪制為一維圖像,每個圖像位于不同的y位置。
plt.imshow需要一個 2D 數組,因此將數組的形狀重新設置為 1 作為第一維,將原始大小作為第二維,從而生成水平圖像。(如果它還不是一個numpy數組,則需要通過)進行轉換。通過該參數,可以設置邊界 x 和 y 值。 顯示每個像素之間的硬邊界。 是為了防止設置固定的寬高比。np.array(ci).reshape(1, -1)extentinterpolation='nearest'aspect='auto'
from matplotlib import pyplot as plt
import numpy as np
# generate six random 1d arrays of different sizes
coeffs = [np.random.uniform(0, 1, np.random.randint(30, 100)) for i in range(6)]
# cA5, cD5, cD4, cD3, cD2, cD1 = coeffs
for i, ci in enumerate(coeffs):
plt.imshow(ci.reshape(1, -1), extent=[0, 1000, i + 0.5, i + 1.5], cmap='inferno', aspect='auto', interpolation='nearest')
plt.ylim(0.5, len(coeffs) + 0.5) # set the y-lim to include the six horizontal images
# optionally relabel the y-axis (the given labeling is 1,2,3,...)
plt.yticks(range(1, len(coeffs) + 1), ['cA5', 'cD5', 'cD4', 'cD3', 'cD2', 'cD1'])
plt.show()

添加回答
舉報
