使用matplotlib-Python创建直方图
我试图用matplotlib创建直方图(x=持续时间列;y=出现次数),但没有成功。这是我的密码:使用matplotlib-Python创建直方图,python,matplotlib,histogram,Python,Matplotlib,Histogram,我试图用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, b
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()
我认为代码没有任何问题。该文件有超过300000行,当我尝试使用1000行的示例运行此代码时,效果很好。问题是文件的大小吗?您可以从我的帐户下载该文件。谢谢。一切正常。问题在于,您的持续时间数据分布在从61到1373043的非常广泛的范围内(请参见
df.duration.description()
),在您看来,只有一个条形图出现了问题:设置
log=True
以获得日志缩放,您会发现一切正常,只是除了第一个之外的所有条都太小,无法在线性缩放中看到:
一切正常。问题在于,您的持续时间数据分布在从61到1373043的非常广泛的范围内(请参见
df.duration.description()
),在您看来,只有一个条形图出现了问题:设置
log=True
以获得日志缩放,您会发现一切正常,只是除了第一个之外的所有条都太小,无法在线性缩放中看到:
以获得清晰、准确的答案和下载文件的努力;)(+1)为了清晰、准确的答案和下载文件的努力;)(+1)