我正在撰寫一些代碼,但在繪制 a 中的最終值時遇到問題,請參閱下面的代碼:
import scipy.stats
import matplotlib.pyplot as plt
import numpy as np
a = np.zeros((1, 1000))
for i in range(1000):
samples = scipy.stats.norm.rvs(mu, sigma, i 1)
fcn = (abs(samples))**3
a[0, i] = (sum(fcn > 13) / len(fcn))
plt.plot(a) # Would like to plot the values in a, row-wise, against their index values. How to do that?
我很確定這很容易,但只要輸入 plt.plot(a) 就會產生一個空圖,其中包含以下形式的訊息:
<matplotlib.lines.Line2D at 0x1fb259b44c0>,
<matplotlib.lines.Line2D at 0x1fb259b4580>,
<matplotlib.lines.Line2D at 0x1fb259b4640>,
<matplotlib.lines.Line2D at 0x1fb259b4700>,
<matplotlib.lines.Line2D at 0x1fb259b47c0>,
<matplotlib.lines.Line2D at 0x1fb259b4880>,
<matplotlib.lines.Line2D at 0x1fb259b4940>,
uj5u.com熱心網友回復:
在您的代碼中,a是具有 1 個專案的二維陣列。
a=a.flatten()
plt.plot(a)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/357829.html
標籤:Python matplotlib 阴谋
上一篇:使用回圈為多列創建子圖
