0
0
Matplotlibdata~10 mins

Text boxes with bbox in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a text box with a bounding box around the text.

Matplotlib
import matplotlib.pyplot as plt

plt.text(0.5, 0.5, 'Hello', bbox=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'boxstyle': 'round', 'facecolor': 'yellow'}
Bfontsize=12
Ccolor='red'
Dalpha=0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Passing color or fontsize directly to bbox instead of a dictionary.
Not using a dictionary for bbox parameter.
2fill in blank
medium

Complete the code to set the bounding box style to 'circle' for the text box.

Matplotlib
import matplotlib.pyplot as plt

plt.text(0.3, 0.7, 'Circle Box', bbox=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'boxstyle': 'square', 'facecolor': 'lightblue'}
B{'boxstyle': 'round', 'facecolor': 'pink'}
C{'boxstyle': 'larrow', 'facecolor': 'orange'}
D{'boxstyle': 'circle', 'facecolor': 'lightgreen'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'square' or 'round' instead of 'circle' for the boxstyle.
Not passing a dictionary to bbox.
3fill in blank
hard

Fix the error in the code to properly add a text box with a bounding box and a red edge color.

Matplotlib
import matplotlib.pyplot as plt

plt.text(0.6, 0.4, 'Edge Color', bbox=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A{'boxstyle': 'round', 'facecolor': 'white', 'color': 'red'}
B{'boxstyle': 'round', 'facecolor': 'white', 'edgecolor': 'red'}
C{'boxstyle': 'round', 'facecolor': 'white', 'linewidth': 2}
D{'boxstyle': 'round', 'facecolor': 'white', 'bordercolor': 'red'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'color' or 'bordercolor' instead of 'edgecolor'.
Not passing a dictionary to bbox.
4fill in blank
hard

Fill both blanks to create a text box with a shadow effect and a dashed edge.

Matplotlib
import matplotlib.pyplot as plt

plt.text(0.2, 0.8, 'Shadow Box', bbox=[1], [2])
plt.show()
Drag options to blanks, or click blank then click option'
A{'boxstyle': 'round', 'facecolor': 'lightgrey', 'alpha': 0.5}
B{'boxstyle': 'round', 'facecolor': 'white', 'edgecolor': 'black'}
Cedgecolor='black', linestyle='--'
D{'boxstyle': 'round', 'facecolor': 'yellow', 'edgecolor': 'blue'}
Attempts:
3 left
💡 Hint
Common Mistakes
Putting all keys in one dictionary instead of splitting into two.
Using solid line style instead of dashed.
5fill in blank
hard

Fill all three blanks to create a text box with a fancy box style, green face color, and bold font weight.

Matplotlib
import matplotlib.pyplot as plt

plt.text(0.4, 0.6, 'Fancy Box', bbox=[1], fontweight=[2], color=[3])
plt.show()
Drag options to blanks, or click blank then click option'
A{'boxstyle': 'fancy', 'facecolor': 'green'}
B'bold'
C'black'
D'normal'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'normal' fontweight instead of 'bold'.
Not passing a dictionary to bbox.
Using wrong color strings.