0
0
Matplotlibdata~10 mins

Alpha transparency for overlap 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 set the transparency of the scatter plot points.

Matplotlib
import matplotlib.pyplot as plt

plt.scatter([1, 2, 3], [4, 5, 6], alpha=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A1.5
B0.5
C-0.3
D'0.5'
Attempts:
3 left
💡 Hint
Common Mistakes
Using alpha values greater than 1 or less than 0 causes errors.
Passing alpha as a string instead of a number.
2fill in blank
medium

Complete the code to plot two overlapping scatter plots with transparency.

Matplotlib
import matplotlib.pyplot as plt

plt.scatter([1, 2, 3], [4, 5, 6], alpha=[1], color='red')
plt.scatter([2, 3, 4], [5, 6, 7], alpha=0.3, color='blue')
plt.show()
Drag options to blanks, or click blank then click option'
A0.8
B2
C-1
D'0.8'
Attempts:
3 left
💡 Hint
Common Mistakes
Using alpha values outside the 0-1 range.
Passing alpha as a string.
3fill in blank
hard

Fix the error in the code to correctly apply transparency to the scatter plot.

Matplotlib
import matplotlib.pyplot as plt

plt.scatter([1, 2, 3], [4, 5, 6], alpha=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'0.5'
B2
C0.5
D-0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Passing alpha as a string causes a TypeError.
Using values outside the 0-1 range causes ValueError.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Matplotlib
words = ['data', 'ai', 'science', 'ml']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length as the value.
Checking if the word (string) is greater than 3 instead of length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 4.

Matplotlib
words = ['apple', 'data', 'science', 'ai']
result = [1]: [2] for w in words if [3]
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
Clen(w) > 4
Dw.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using w.lower() instead of w.upper() for keys.
Not filtering words by length correctly.