0
0
Matplotlibdata~20 mins

Why histograms show distributions in Matplotlib - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Histogram Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What does this histogram represent?
Look at the code that creates a histogram. What does the histogram show about the data?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data = np.random.normal(loc=0, scale=1, size=1000)
plt.hist(data, bins=20)
plt.show()
AIt shows the sum of all data points in the dataset.
BIt shows the exact values of each data point as dots on the plot.
CIt shows the frequency of data points in each range (bin), representing the data distribution.
DIt shows the average value of the data points only.
Attempts:
2 left
💡 Hint
Think about what a histogram does with data points and bins.
data_output
intermediate
2:00remaining
Number of bins effect on histogram
What happens to the histogram output if you increase the number of bins from 5 to 50 for the same data?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data = np.random.uniform(0, 10, 1000)
plt.hist(data, bins=5)
plt.show()
plt.hist(data, bins=50)
plt.show()
AThe histogram with 50 bins shows more detailed distribution with smaller ranges per bin.
BThe histogram with 50 bins shows fewer bars than the one with 5 bins.
CBoth histograms look exactly the same.
DThe histogram with 5 bins shows more detail than the one with 50 bins.
Attempts:
2 left
💡 Hint
More bins means dividing data into smaller groups.
visualization
advanced
2:30remaining
Identify the distribution type from histogram
Given the histogram plot code below, what type of distribution does the data most likely have?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data = np.random.exponential(scale=1.0, size=1000)
plt.hist(data, bins=30)
plt.show()
AThe data follows an exponential distribution with many small values and a long tail.
BThe data follows a uniform distribution with equal frequency across bins.
CThe data follows a normal distribution with a symmetric bell shape.
DThe data follows a bimodal distribution with two peaks.
Attempts:
2 left
💡 Hint
Look for a shape with a peak near zero and a tail stretching right.
🧠 Conceptual
advanced
2:00remaining
Why histograms are useful for understanding data
Why do data scientists use histograms to understand data distributions?
ABecause histograms remove all noise from data to show only clean values.
BBecause histograms list every single data point in the dataset.
CBecause histograms calculate the exact mean and median values automatically.
DBecause histograms visually summarize how data points are spread across ranges, revealing patterns and outliers.
Attempts:
2 left
💡 Hint
Think about what visual summaries help you see quickly.
🔧 Debug
expert
2:30remaining
Why does this histogram code produce an error?
Look at the code below. Why does it raise an error when trying to plot the histogram?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data = np.random.normal(0, 1, 100)
plt.hist(data, bins='ten')
plt.show()
ABecause plt.show() must be called before plt.hist().
BBecause 'bins' parameter must be an integer or sequence, not a string like 'ten'.
CBecause plt.hist cannot plot data from numpy arrays.
DBecause np.random.normal requires three arguments, but only two are given.
Attempts:
2 left
💡 Hint
Check the type of the 'bins' argument.