0

I'm trying to create histogram (x = duration column; y = count of occurrences) with matplotlib but without success. Here is my code:

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

I dont think there is anything wrong with the code. The file has over 300 000 rows and when I tried run this code with sample of 1000 rows it worked just fine. Could it be that the problem is the size of the file? You can download the file from my github account. Thank you.

1 Answer 1

2

Everything works correctly. The issue is just that your duration data are spread over a very wide range from 61 to 1,373,043 (see df.duration.describe()) and it seems to you that there's something wrong as you see just one bar:
enter image description here

Set log=True to get a log scaling and you'll discover that everything is OK, just all bars but the first one are too small to be visible in a linear scaling: enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

for the clean, precise answer and the effort of downloading the file ;) (+1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.