A horizontal grouped bar chart shows bars side-by-side along the horizontal axis. Each group represents a category, and bars within a group represent sub-categories. It helps compare multiple groups across categories.
Click to reveal answer
intermediate
How do you control the position of bars in a horizontal grouped bar chart in matplotlib?
You control bar positions by setting the y-values with an offset for each group. Use numpy arrays and add/subtract a fixed height to shift bars side-by-side vertically.
Click to reveal answer
beginner
Which matplotlib function is used to create horizontal bars?
The function plt.barh() creates horizontal bars in matplotlib.
Click to reveal answer
beginner
Why use horizontal grouped bars instead of vertical grouped bars?
Horizontal bars are easier to read when category names are long or when you want to emphasize comparison across categories horizontally.
Click to reveal answer
intermediate
What parameters are important to set for clear horizontal grouped bars?
Important parameters include bar height (height in barh), y positions with offsets, colors for groups, and labels for clarity.
Click to reveal answer
Which matplotlib function creates horizontal bars?
Aplt.plot()
Bplt.bar()
Cplt.barh()
Dplt.scatter()
✗ Incorrect
plt.barh() is used for horizontal bars, while plt.bar() is for vertical bars.
In a horizontal grouped bar chart, how do you place bars side-by-side?
ABy changing the y positions with offsets
BBy changing the x positions with offsets
CBy changing the bar colors
DBy changing the bar heights
✗ Incorrect
Bars are placed side-by-side by adjusting their y positions with offsets.
What does each group in a grouped bar chart represent?
AThe color of the bars
BA single data point
CThe x-axis label
DA category with multiple sub-categories
✗ Incorrect
Each group represents a category containing multiple sub-categories shown as bars.
Why might you choose horizontal bars over vertical bars?
ATo save vertical space
BTo better display long category names
CBecause horizontal bars are faster to plot
DBecause vertical bars cannot be grouped
✗ Incorrect
Horizontal bars help display long category names more clearly.
Which parameter controls the thickness of bars in plt.barh()?
Aheight
Bwidth
Csize
Dlength
✗ Incorrect
In plt.barh(), the 'height' parameter controls the thickness of the bars.
Explain how to create a horizontal grouped bar chart using matplotlib.
Think about how to position bars side-by-side horizontally.
You got /5 concepts.
Describe when and why you would use horizontal grouped bars instead of vertical grouped bars.
Consider the visual clarity and label length.
You got /4 concepts.
Practice
(1/5)
1.
What is the main purpose of using horizontal grouped bars in a chart?
easy
A. To compare multiple categories side by side horizontally
B. To show data as a pie chart
C. To display data only vertically
D. To create a line graph
Solution
Step 1: Understand the chart type
Horizontal grouped bars place bars side by side horizontally to compare groups.
Step 2: Identify the purpose
This layout helps compare multiple categories clearly across groups.
Final Answer:
To compare multiple categories side by side horizontally -> Option A
How would you create a horizontal grouped bar chart to compare sales by product and year, ensuring product labels appear centered between grouped bars?
hard
A. Use plt.plot to draw lines for each product
B. Use plt.barh with positions shifted by width and set yticks at x + width/2
C. Use plt.barh with same positions for both years and set yticks at x
D. Use plt.bar with positions shifted by width and set xticks at x + width/2
Solution
Step 1: Use plt.barh with shifted positions
Shift positions by width for each year to group bars horizontally side by side.
Step 2: Set yticks at middle of grouped bars
Set yticks at x + width/2 so product labels appear centered between bars.
Final Answer:
Use plt.barh with positions shifted by width and set yticks at x + width/2 -> Option B