根據 matplotlib 檔案,x 和/或 y 可能是二維陣列,在這種情況下,列被視為不同的資料集。當我按照matplotlib 頁面中的
如果我分別繪制它們,結果很好:
fig, ax = plt.subplots()
ax.plot(x,chi2_2,'b')
ax.plot(x,chi2_5,'r')

除了使用帶有 Float64 而不是 Int64 的二維陣列之外,我無法弄清楚示例和我的案例之間有什么區別。任何幫助表示贊賞。
uj5u.com熱心網友回復:
看起來reshape沒有做你期望它做的事情。我認為您正在尋找的功能是transpose而不是reshape.
from scipy.stats import chi2
x = np.linspace(0,5,1000)
chi2_2, chi2_5 = chi2.pdf(x,2), chi2.pdf(x,5)
y = np.array((chi2_2,chi2_5)).T
y2 = np.array((chi2_2,chi2_5)).reshape(1000,2)
print(np.array_equal(y,y2))
fig, ax = plt.subplots()
ax.plot(x,y)
plt.show()
使用transpose回傳所需的情節和np.array_equal(y,y2)被False
確認2個陣列是不一樣的。
下面是輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/361975.html
標籤:麻木的 matplotlib
