简体   繁体   中英

Plotting an array in Python - How to do it?

I am writing some code but have problems plotting the final values in a, please see code below:

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? 

I am quite sure this is easy, but just typing plt.plot(a) yields an empty plot with messages of the form :

<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>,

In your code, a is 2-d array with 1 item.

a=a.flatten()
plt.plot(a)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM