[英]Create Histogram with matplotlib - Python
我正在尝试使用 matplotlib 创建直方图(x = 持续时间列;y = 出现次数)但没有成功。 这是我的代码:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel ("J:/edinburgh_bikes.xlsx")
x = df['duration'].to_numpy()
fig, ax = plt.subplots()
# the histogram of the data
n, bins, patches = plt.hist(x, 50, density=True, facecolor='g', alpha=0.75)
plt.xlabel('duration')
plt.ylabel('count')
plt.title('Histogram of bike ride duration')
plt.grid(True)
plt.show()
我不认为代码有什么问题。 该文件有超过 300 000 行,当我尝试使用 1000 行的示例运行此代码时,它工作得很好。 难道问题出在文件的大小上? 您可以从我的github帐户下载文件。 谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.