0
0
Matplotlibdata~20 mins

Histogram vs bar chart distinction in Matplotlib - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Histogram vs Bar Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference between histogram and bar chart

Which statement correctly describes the main difference between a histogram and a bar chart?

AHistograms and bar charts are the same and can be used interchangeably for any data type.
BA histogram uses separated bars to show categorical data, while a bar chart uses adjacent bars for continuous data.
CBoth histogram and bar chart show categorical data but histograms use colors to differentiate bars.
DA histogram shows the frequency distribution of continuous data using adjacent bars, while a bar chart displays categorical data with separated bars.
Attempts:
2 left
💡 Hint

Think about whether the data is continuous or categorical and how bars are placed.

Predict Output
intermediate
2:00remaining
Output of histogram code with matplotlib

What will be the output of this code snippet?

Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data = np.random.normal(0, 1, 1000)
plt.hist(data, bins=5)
plt.show()
AA scatter plot of 1000 points around zero.
BA plot with 5 separated bars each representing a category.
CA plot with 5 adjacent bars showing frequency of data in 5 ranges.
DA line plot showing data values sorted.
Attempts:
2 left
💡 Hint

Look at the function used: plt.hist and the bins parameter.

data_output
advanced
2:00remaining
Data output from bar chart data preparation

Given this data preparation code, what is the output of counts?

Matplotlib
categories = ['A', 'B', 'C']
values = [10, 15, 7]
counts = dict(zip(categories, values))
print(counts)
A{'A': 10, 'B': 15, 'C': 7}
B{10: 'A', 15: 'B', 7: 'C'}
C['A', 'B', 'C', 10, 15, 7]
DError: cannot zip lists of different lengths
Attempts:
2 left
💡 Hint

Think about what zip and dict do together.

visualization
advanced
2:00remaining
Identify the plot type from description

You see a plot with bars touching each other representing ranges of ages and their counts. What type of plot is this?

ABar chart
BHistogram
CPie chart
DLine chart
Attempts:
2 left
💡 Hint

Bars touching usually mean continuous data grouped in bins.

🔧 Debug
expert
2:00remaining
Why does this bar chart code raise an error?

What error does this code raise and why?

import matplotlib.pyplot as plt
categories = ['X', 'Y', 'Z']
values = [5, 7]
plt.bar(categories, values)
plt.show()
AValueError: x and height must have same length because categories and values differ in length.
BTypeError: categories must be numbers, not strings.
CSyntaxError: missing colon after plt.bar call.
DNo error, the plot shows bars for X and Y only.
Attempts:
2 left
💡 Hint

Check if the lists passed to plt.bar have the same length.