Challenge - 5 Problems
BBox Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput 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()
Attempts:
2 left
💡 Hint
Check the 'edgecolor' parameter inside bbox dictionary.
✗ Incorrect
The 'edgecolor' parameter sets the border color of the text box. Here it is set to 'red'.
❓ data_output
intermediateNumber 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()
Attempts:
2 left
💡 Hint
Count how many times ax.text is called inside the loop.
✗ Incorrect
The loop runs 3 times, each time creating one text box with bbox.
🔧 Debug
advancedIdentify 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()
Attempts:
2 left
💡 Hint
Check if 'circle' is a valid boxstyle in matplotlib.
✗ Incorrect
'circle' is not a valid boxstyle name in matplotlib, causing a ValueError.
❓ visualization
advancedEffect 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()
Attempts:
2 left
💡 Hint
Alpha controls transparency from 0 (transparent) to 1 (opaque).
✗ Incorrect
Alpha=0.5 means the red background is half transparent, so you see some background behind it.
🧠 Conceptual
expertUnderstanding bbox boxstyle options
Which of these is NOT a valid boxstyle option for bbox in matplotlib text boxes?
Attempts:
2 left
💡 Hint
Check matplotlib documentation for valid boxstyle names.
✗ Incorrect
'diamond' is not a recognized boxstyle in matplotlib, unlike 'round', 'square', and 'larrow'.
