简体   繁体   English

直方图未绘制

[英]Histogram not being plotted

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. 这是我的代码,用于在pycharm中绘制直方图,但是它什么也没显示,只是打印print语句。 Need help ! 需要帮忙 !

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()

You have to create a plot first with plt.plot(data) and then show it with plt.show() . 您必须先使用plt.plot(data)创建一个图,然后使用plt.show()显示它。 To plot the histogram, you call plt.hist(data) before plt.show() . 要绘制直方图,请在plt.show()之前调用plt.hist(data) plt.show()

You have to actually tell matplotlib what you want to plot - in this case, the histogram of data . 您实际上必须告诉matplotlib您想要绘制的内容-在这种情况下,就是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)

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 : 您不应该使用plt.interactive(True) ,可以使用plt.interactive(False) 。然后可以运行代码,并显示以下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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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