Which function is used to create a vertical bar chart in Matplotlib?
A
plt.bar() B
plt.vbar() C
plt.barchart() D
plt.barplot()
Analysis & Theory
`plt.bar()` is used to create vertical bar charts in Matplotlib.
Which function is used to create a horizontal bar chart?
A
plt.hbar() B
plt.barh() C
plt.bar(horizontal=True) D
plt.hbarplot()
Analysis & Theory
`plt.barh()` creates horizontal bar charts.
What parameter sets the width of bars in `plt.bar()`?
A
thickness B
barwidth C
width D
size
Analysis & Theory
`width` sets the thickness of the bars in a bar chart.
How can you assign different colors to each bar?
A
Use `color='random'` B
Use a list of colors in `color` parameter C
Use `plt.colorbar()` D
You can't change bar colors
Analysis & Theory
You can pass a list of color names or values to the `color` parameter in `plt.bar()`.
What does `plt.bar(x, height)` require `x` to be?
A
A single number B
A string C
A list of x-axis positions D
A tuple of bar widths
Analysis & Theory
`x` should be a list of positions where bars will be drawn.
How do you add values above each bar?
A
Use `plt.label()` B
Use `plt.annotate()` or `plt.text()` C
Use `bar.text()` D
Use `plt.barlabel()` only
Analysis & Theory
`plt.text()` or `plt.annotate()` is used to add custom text above bars.
What does `align='center'` do in `plt.bar()`?
A
Centers bar labels B
Centers bars on the x positions C
Aligns bars vertically D
Centers bars to the top
Analysis & Theory
`align='center'` places the bar so that its center is aligned with the x position.
What happens if two bars have the same x position?
A
They merge into one B
The second one overwrites the first C
They stack by default D
They overlap
Analysis & Theory
Bars with the same x value overlap unless you manually offset them.
How do you make grouped bar charts?
A
Use `plt.bar()` with labels B
Use offset x positions for each group C
Use `plt.groupbar()` D
Set `group=True`
Analysis & Theory
Grouped bar charts are created by plotting multiple `plt.bar()` calls with slightly shifted x positions.
How do you display a legend for bar charts?
A
Use `label=` in `plt.bar()` and call `plt.legend()` B
Bar charts cannot have legends C
Use `bar.legend()` D
Use `plt.title()`
Analysis & Theory
Set `label=` in `plt.bar()` and call `plt.legend()` to display the legend.