0
0
Matplotlibdata~20 mins

Text boxes with bbox in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
BBox Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of text box with bbox style
What will be the color of the text box border in the following matplotlib code?
Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.text(0.5, 0.5, 'Hello', bbox=dict(facecolor='yellow', edgecolor='red', boxstyle='round'))
plt.show()
AThe border color is red
BThe border color is yellow
CThe border color is black
DThere is no border color
Attempts:
2 left
💡 Hint
Check the 'edgecolor' parameter inside bbox dictionary.
data_output
intermediate
2:00remaining
Number of text boxes created
How many text boxes with bounding boxes will be displayed by this code?
Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
for i in range(3):
    ax.text(i, i, f'Text {i}', bbox=dict(facecolor='blue', alpha=0.3))
plt.show()
A4
B1
C3
D0
Attempts:
2 left
💡 Hint
Count how many times ax.text is called inside the loop.
🔧 Debug
advanced
2:00remaining
Identify the error in bbox usage
What error will this code raise when run?
Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.text(0.5, 0.5, 'Error test', bbox=dict(facecolor='green', edgecolor='blue', boxstyle='circle'))
plt.show()
ASyntaxError: invalid syntax
BNo error, plot shows correctly
CTypeError: bbox must be a dict
DValueError: Unknown boxstyle 'circle'
Attempts:
2 left
💡 Hint
Check if 'circle' is a valid boxstyle in matplotlib.
visualization
advanced
2:00remaining
Effect of alpha in bbox facecolor
Which option best describes the visual effect of alpha=0.5 in the bbox facecolor?
Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.text(0.5, 0.5, 'Alpha test', bbox=dict(facecolor='red', alpha=0.5))
plt.show()
AThe text box background is fully transparent
BThe text box background is semi-transparent red
CThe text box background is fully opaque red
DThe text box background is blue
Attempts:
2 left
💡 Hint
Alpha controls transparency from 0 (transparent) to 1 (opaque).
🧠 Conceptual
expert
2:00remaining
Understanding bbox boxstyle options
Which of these is NOT a valid boxstyle option for bbox in matplotlib text boxes?
Adiamond
Bsquare
Cround
Dlarrow
Attempts:
2 left
💡 Hint
Check matplotlib documentation for valid boxstyle names.