Reputation: 65
data = [1, 2, 1, 3, 3, 1, 4, 2]
print("mean : ",np.mean(data))
print("Standard deviation : ",np.std(data))
print("max : ",np.max(data))
print("min : ",np.min(data))
import matplotlib.pyplot as plt
plt.interactive(True)
plt.show(data)
This is my code for drawing a histogram in pycharm but it ain't showing anything , just printing the print statement. Need help !
Upvotes: 2
Views: 3490
Reputation: 2950
You should not use plt.interactive(True)
instesd of this you can use plt.interactive(False)
.Then You can run you code and you will show graph
:
from matplotlib import pyplot as plt
from numpy import asarray
data = asarray([1, 2, 1, 3, 3, 1, 4, 2])
print("mean : ", data.mean())
print("Standard deviation : ", data.std())
print("max : ", data.max())
print("min : ", data.min())
# plt.interactive(True)
plt.interactive(False)
plt.plot(data)
plt.show()
#plot histogram
plt.hist(data)
plt.show()
Upvotes: 1
Reputation: 6026
You have to create a plot first with plt.plot(data)
and then show it with plt.show()
. To plot the histogram, you call plt.hist(data)
before plt.show()
.
Upvotes: 1
Reputation: 1091
You must plot the histogram, here is how:
from matplotlib.pyplot import subplots, show
data = [1, 2, 1, 3, 3, 1, 4, 2]
fig, ax = subplots()
ax.hist(data)
show()
Upvotes: 3
Reputation: 2095
You have to actually tell matplotlib what you want to plot - in this case, the histogram of data
.
data = [1, 2, 1, 3, 3, 1, 4, 2]
print("mean : ",np.mean(data))
print("Standard deviation : ",np.std(data))
print("max : ",np.max(data))
print("min : ",np.min(data))
import matplotlib.pyplot as plt
plt.interactive(True)
plt.hist(data)
plt.show(data)
Upvotes: 1