[英]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.